[Solved] Help needed with a javascript bug. Color Guessing Game. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

[Solved] Help needed with a javascript bug. Color Guessing Game.

My program is a color choosing game, I randomly set a color per div and randomly choose one . As you play , some times the chosen color (the one you're supposed to find) , isn't one of the colors in the div. Then none of the answers are correct . https://code.sololearn.com/W3BpYFPY42FJ/?ref=app

21st Aug 2021, 7:38 PM
Carolyn-G
Carolyn-G - avatar
7 Antworten
+ 2
The problem only occurs when chosenN equals zero. You can add +1 to line 28: var chosenN = Math.floor(Math.random()*6+1); This will ensure you get a random number from 1 to 6 instead of a number from 0 to 5. I didn't correct your code, I just logged chosenN to the console and numbered each div. This was done for visual effect. https://code.sololearn.com/WrmuDT0I2LrA
22nd Aug 2021, 3:39 AM
ODLNT
ODLNT - avatar
+ 2
Thanks Vasiliy ,Brain & Bones and ODLNT , you have been a great help , thanks for the help and the valuable suggestions.
22nd Aug 2021, 3:52 AM
Carolyn-G
Carolyn-G - avatar
+ 1
You're welcome 😊
22nd Aug 2021, 4:01 AM
ODLNT
ODLNT - avatar
+ 1
ODLNT bravo! 👏👏👏👏👏 Carolyn-G on my own behalf, I just want to add that the iteration must be started from 1, since there is no 0th child. ☺️
22nd Aug 2021, 5:10 AM
Solo
Solo - avatar
+ 1
Thanks Vasiliy , it's edited now 👍
22nd Aug 2021, 6:20 AM
Carolyn-G
Carolyn-G - avatar
0
Great code, works well. I did not find any color mismatches, I guessed most of them. ☺️ If we add the statistics of responses, then in general it would be great.
21st Aug 2021, 8:13 PM
Solo
Solo - avatar
0
I see your problem, why dont you add the six colors of that round into an array and then the color you are to guess can be randomly pick from that array
21st Aug 2021, 10:34 PM
Brain & Bones
Brain & Bones - avatar