2018-09-30 23:01:58 +01:00
---
id: bd7993c9c69feddfaeb8bdef
title: Store Multiple Values in one Variable using JavaScript Arrays
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/crZQWAm'
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
With JavaScript < code > array< / code > variables, we can store several pieces of data in one place.
2018-10-08 01:01:53 +01:00
You start an array declaration with an opening square bracket, end it with a closing square bracket, and put a comma between each entry, like this:
2018-09-30 23:01:58 +01:00
< code > var sandwich = ["peanut butter", "jelly", "bread"]< / code > .
< / section >
## Instructions
< section id = 'instructions' >
Modify the new array < code > myArray< / code > so that it contains both a < code > string< / code > and a < code > number< / code > (in that order).
< strong > Hint< / strong > < br > Refer to the example code in the text editor if you get stuck.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: < code > myArray</ code > should be an < code > array</ code > .
2018-10-20 21:02:47 +03:00
testString: assert(typeof myArray == 'object', '< code > myArray< / code > should be an < code > array< / code > .');
2018-10-04 14:37:37 +01:00
- text: The first item in < code > myArray</ code > should be a < code > string</ code > .
2018-10-20 21:02:47 +03:00
testString: assert(typeof myArray[0] !== 'undefined' & & typeof myArray[0] == 'string', 'The first item in < code > myArray< / code > should be a < code > string< / code > .');
2018-10-04 14:37:37 +01:00
- text: The second item in < code > myArray</ code > should be a < code > number</ code > .
2018-10-20 21:02:47 +03:00
testString: assert(typeof myArray[1] !== 'undefined' & & typeof myArray[1] == 'number', 'The second item in < code > myArray< / code > should be a < code > number< / code > .');
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
// Example
var ourArray = ["John", 23];
// Only change code below this line.
var myArray = [];
```
< / div >
### After Test
< div id = 'js-teardown' >
```js
2018-10-20 21:02:47 +03:00
(function(z){return z;})(myArray);
2018-09-30 23:01:58 +01:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
var myArray = ["The Answer", 42];
```
< / section >