0

Issue with code

Everything works but my result function/button <!DOCTYPE html> <html> <head> </head> <body> <script> result=1; function changevar(){ v1=prompt("Insert your first option"); v2=prompt("Insert your second option"); v3=prompt("Insert your last option"); } function startjs(){ opa="hi"; opb="hi"; opc="hi"; opra = ("People like"+" "+v1); oprb = ("People like"+" "+v2); oprc = ("People like"+" "+v3); opa =prompt("How many people like"+" "+v1); opb =prompt("How many people like"+" "+v2); opc =prompt("How many people like"+" "+v3); result=opa+" "+opra+" "+opb+" "+oprb+" "+opc+" "+oprc; } function result(){ alert(result); if(opa>opb&&opa>opc){ alert("The most people like"+" "+v1); } if(opb>opc&&opb>opa){ alert ("The most people like"+" "+v2); } if(opc>opa&&opc>opb){ alert ("The most people like"+" "+v3); } if(opa==opb&&opa>opc){ alert ("The most people like either "+" "+v1+" "+"or"+" "+v2); } if(opa==opc&&opa>opb){ alert ("The most people like either "+" "+v1+" "+"or"+" "+v3); } if(opb==opc&&opb>opa) { alert ("The most people like either "+" "+v2+" "+"or"+" "+v3); } } </script> <button id=button1 onclick="startjs()">Start</button> <br> <br> <button id=button2 onclick="changevar()">Change Variables</button> <br> <br> <button id=button3 onclick="result()">Result</button> </body> </html>

11th May 2017, 12:59 AM
FOXES ARE SICK6969
2 Answers
+ 2
• Javascript code must be called and run after Html code. • You must declare all your variables in global. • The function result cannot be same name as variable result. Check out this code.. https://code.sololearn.com/W8KRuk6cMrHR/?ref=app
11th May 2017, 1:12 AM
CalviŐ˛
CalviŐ˛ - avatar
0
Thank you!
11th May 2017, 1:14 AM
FOXES ARE SICK6969