0

[Solved] Can anyone figure out what's wrong in my code?

Why only 5 and 6 come up on clicking the button? https://code.sololearn.com/Wd7QvYer8elF/?ref=app

15th Jun 2021, 2:11 AM
Shobhit :)
Shobhit :) - avatar
3 ответов
+ 2
because you write a serie of 'if', and on last (num==5) you add an 'else'... so finally, if num==5 src is set to dice 5, else src is set to dice 6, despite another one was attributed previously ^^ instead of if..else if..else, I would advise to just do: img.src = images[num]; ;)
15th Jun 2021, 2:28 AM
visph
visph - avatar
+ 2
Thanks visph 🤗🤗
15th Jun 2021, 2:52 AM
Shobhit :)
Shobhit :) - avatar
15th Jun 2021, 6:16 AM
Shobhit :)
Shobhit :) - avatar