Exercice Through the hard times


#1

<>
Hello, it might be a stupid question, but I don't get why the formula doesn't work without me having to change it. First I had to remove 'var answer = ' because I would not get a true or false in the console.

58 is not a multiple of 8 and it returns true ("Real multiples will return false") BUT if I put a multiple of 8 instead, it does show "true" too... hum, why?

And is there a way of checking this formula without having to put a specific number of the array but checking the whole array?



multiplesOfEight[58] % 8 !== 0;


#2

You're supposed to put a argument for the array multiplesOfEight in the [].

var multiplesOfEight = [8,16,24,32,40,58];
var answer = multiplesOfEight[/*insert the correct number here*/] % 8 !== 0;
console.log(answer);

#3

It still returns true for any number...


#4

Sorry, I didn't explain that right. The number that you should put in these [] is a place marker for the array multiplesOfEight.

var multiplesOfEight = [8,16,24,32,40,58];
var answer = multiplesOfEight[5] % 8 !== 0;

Here the computer is dividing the 6th item in the array multiplesOfEight, not the number 5.


#5

Yes now i get it thanks
is there a way to check the whole array at once? Or you would have to do a for/if construction?


#6

You could use a for loop. Here's the syntax

var multiplesOfEight = [8,16,24,32,40,58];
for (var i = 0; i < multiplesOfEight.length; i++) {
var answer = multiplesOfEight[i] % 8 !== 0;
console.log(answer);
};

#7

yes it's true, thank you!


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.