Skip to content
Advertisement

Pick and return a pair of values from an array into two different outputs. JavaScript

I have a function that takes a random element from an array and, at the press of a button, returns the random value to an output. The code is as follows:

JavaScript
JavaScript

So far the code is working perfectly, returning to the output a random value from the “questions” array. However, I need to take it a step further. I need to return two inseparable values from the array, and each of these values needs to be returned in a different output (the “questions” value goes to the “question” output, and the “examples” value goes to “example” output)

I therefore need to transform my “randomQuestion” function into one that returns, for example, the value “What is your name” for the output “question”, and the value “Matheus” for the output “example”, and so on.

JavaScript
JavaScript

Advertisement

Answer

you were almost there

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement