Social Icons

Pages

Wednesday, November 30, 2016

Introduction to Objects I 2/33

Through the hard times...
We know two ways of storing data types. We can use variables or arrays. We use variables to store data (like strings or numbers) that we’d later want to access.
An array is exactly the same as a variable in that it stores data. The difference is that an array can store many more values while a variable can only store one.
To access arrays, we use bracket notation and remember that arrays use 0-based indexing (i.e., the first value in an array is at position 0).

Instructions
Look at the array multiplesOfEight, and find the one that doesn't fit.
Replace X in line 6 such that the variableanswer is assigned the Boolean value of true.
?
Hint
Array indexes start at 0. So the first element of an array has index 0.
For example, the first element ofmultiplesOfEight is 8, and its index is 0. The third element of multiplesOfEight is24, and its index is 2.
The operator !== means "does NOT equal". For example,
10 !== 5;
evaluates to true because 10 does not equal 5.


// Here is an array of multiples of 8. But is it correct?
var multiplesOfEight = [8,16,24,32,40,58];
var X= multiplesOfEight 

// Test to see if a number from the array is NOT a true
// multiple of eight. Real multiples will return false.
var answer = multiplesOfEight[X] % 8 !== 0;

No comments:

Post a Comment