+ 1

I want this code to continuously output

let Array =[ "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "5", "5", "5", "5", "5", "5", "5", "10", "10", "10", "10", "2roll", "2roll", "2roll", "chance", "chance", "4roll", ] var t = 0; var i = 10; const randomIndex = Math.floor(Math.random() * Array.length); const randomElem = Array[randomIndex]; console.log(randomElem); for (var element of randomElem ) { if(element ===1) { t = t + i; console.log(element ) console.log(t) console.log(i) } else { t = t - i; i = i * 2; console.log(element ) console.log(t) console.log(i) } }

8th May 2020, 8:04 AM
Tharun
Tharun - avatar
6 Answers
+ 2
First, Array is a reserved word in JS. Use some other alternatives like arr, etc., Second, you can't iterate a non-iteratable using for..of loop Third, Your question is not clear
8th May 2020, 8:12 AM
deeyae
deeyae - avatar
+ 1
Tharun Hey, I didn’t understand the question. Do you want to get random element from the array continuously?
8th May 2020, 8:08 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
Let me know if this what you are looking for :)) https://code.sololearn.com/W8yiGZ9ewNsZ/?ref=app
8th May 2020, 8:31 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
I want to get random element from array continuously and pass it to for loop and check the conditions and output values
8th May 2020, 9:27 AM
Tharun
Tharun - avatar
0
I want at least 100 outputs
8th May 2020, 9:29 AM
Tharun
Tharun - avatar
0
Arb Rahim badsa you got it ryt but how do I pass the random generated number to for looop
8th May 2020, 10:45 AM
Tharun
Tharun - avatar