Javascript Practice 50: JS Hero - Arrays

 
Question: 

Write a function toArray that takes 2 values and returns these values in an array.

Example: toArray(5, 9) should return the array [5, 9].




Answer: 

function toArray (a,b) {

let array = [a, b]; 
return array 

}




> declare a function toArray
> it has 2 parameters
> we declare a variable array
> we initialize it with an array that contains the two parameters 
> like this [a, b] 
> we return the array

Comments

Popular posts from this blog

Junior Developer Central JS Practice Exercise - 22

Junior Developer Central JS Practice Exercise - 21

Javascript Practice 68: JS Hero - do...while loop