* fix: remove example code from challenge seed * fix: remove declaration from solution * fix: added sum variable back in * fix: reverted description back to original version * fix: added examples to description section * fix: added complete sentence Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: corrected typo Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> * fix: reverted to original desc with formatted code * fix: removed unnecessary code example from description section Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: failiing test on iterate through array with for loop * fix: changed to Only change this line Co-Authored-By: Manish Giri <manish.giri.me@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Manish Giri <manish.giri.me@gmail.com> Co-authored-by: moT01 <tmondloch01@gmail.com>
2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
56bbb991ad1ed5201cd392ca | Access Array Data with Indexes | 1 | https://scrimba.com/c/cBZQbTz | 16158 |
Description
0
.
Example
var array = [50,60,70];
array[0]; // equals 50
var data = array[1]; // equals 60
Note
There shouldn't be any spaces between the array name and the square brackets, like array [0]
. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
Instructions
myData
and set it to equal the first value of myArray
using bracket notation.
Tests
tests:
- text: The variable <code>myData</code> should equal the first value of <code>myArray</code>.
testString: assert((function(){if(typeof myArray !== 'undefined' && typeof myData !== 'undefined' && myArray[0] === myData){return true;}else{return false;}})());
- text: The data in variable <code>myArray</code> should be accessed using bracket notation.
testString: assert((function(){if(code.match(/\s*=\s*myArray\[0\]/g)){return true;}else{return false;}})());
Challenge Seed
// Setup
var myArray = [50,60,70];
// Only change code below this line
After Test
if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,z){return 'myArray = ' + JSON.stringify(y) + ', myData = ' + JSON.stringify(z);})(myArray, myData);}
Solution
var myArray = [50,60,70];
var myData = myArray[0];