-3
I’m trying to solve an exercise, and I’m having a hard time finding out where I’m going wrong, some hint?
Exercise :
Program a function buscarDivisivelPor
which receives two parameters, one array
of numbers and a test number, returning the first number of the array
that is divisible by the given number and other than zero. If no array
pass the test, return the text "No valid number found!".
My code :
function buscarDivisivelPor(array, num) {
for ( var i = 0; i < array.length; i++) {
if( (array[i] % num ) && (!0) ){
console.log(array[i])
break
} else {
console.log("Nenhum número válido encontrado!")
}
}
}
//Exemplo de array : [0, 9, 4, 7, 128, 42, -1, 301, -5] num : 2
//A resposta deveria ser 4
what’s the problem? if you didn’t report what’s happening
– novic
I am trying to pass an array in the array parameter, and a random number in the one parameter to perform the account. However, it is not returning as it should. @Virgilionovic
– xBrn0xy