Experimenting with JS return statement... help [SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Experimenting with JS return statement... help [SOLVED]

Is return only used for operations? +, -, /, * Or can you use it for other things too, like what I’m attempting in my code below? It’s very clear what I’m trying to do in the following code. YOUR LIST TO BE RANDOMIZED[Math.floor...] https://code.sololearn.com/WN3noR44IKMV/?ref=app

7th Aug 2020, 8:31 AM
Ginfio
Ginfio - avatar
2 Answers
+ 3
You can put anything in the return statement. The problem is that on line 18, you are multiplying a number by an array Math.floor(Math.random()*list) Here, Math.random() returns a number which you are multiplying with list, an array. Replace `list` with `list.length` and your code should work fine
7th Aug 2020, 8:35 AM
XXX
XXX - avatar
+ 2
XXX OMG. what am i thinking.? I don’t know how did I forgot about that. I guess I just needed someone to remind ne. Thank.You()
7th Aug 2020, 8:39 AM
Ginfio
Ginfio - avatar