html - Why is my JavaScript code not calling my function? -
i new javascript , made basic choose own adventure game switch statement. when attempt call function using button unsuccessful. javascript alone this.
function choosegame(){ var troll = prompt("you walking through forest on way gamestop. come across troll guarding bridge there, says if pay him let by. pay, kill, or challenge him game of chess?").touppercase(); switch(troll){ case'pay': var money = prompt("do have money").touppercase(); var amount = prompt("is $50?").touppercase(); if (money && amount === "yes"){ console.log("you pay him , steal game wanted, caught, , go prison."); }else{ console.log("he broke legs , stole shoes, not you'd needing them."); } break; case'kill': var weapon = prompt("do have weapon?").touppercase(); var friend = prompt("do have friends you?").touppercase(); if (weapon || friend === "yes"){ console.log("you break legs , take money buying multiple games."); }else{ console.log("he brings personal torture chamber , laughs @ pain eternity."); } break; case'challenge him game of chess': var clever = prompt("are clever?").touppercase(); var ability = prompt("are @ chess?").touppercase(); if (clever || ability === "yes"){ console.log("you beat him , go on way gamestop."); }else{ console.log("you aren't clever or @ chess, why did challenge troll game?"); } break; }; }
with html looks this.
<html> <head> <script language = "javacript"> function choosegame(){ var troll = prompt("you walking through forest on way gamestop. come across troll guarding bridge there, says if pay him let by. pay, kill, or challenge him game of chess?").touppercase(); switch(troll){ case'pay': var money = prompt("do have money").touppercase(); var amount = prompt("is $50?").touppercase(); if (money && amount === "yes"){ console.log("you pay him , steal game wanted, caught, , go prison."); }else{ console.log("he broke legs , stole shoes, not you'd needing them."); } break; case'kill': var weapon = prompt("do have weapon?").touppercase(); var friend = prompt("do have friends you?").touppercase(); if (weapon || friend === "yes"){ console.log("you break legs , take money buying multiple games."); }else{ console.log("he brings personal torture chamber , laughs @ pain eternity."); } break; case'challenge him game of chess': var clever = prompt("are clever?").touppercase(); var ability = prompt("are @ chess?").touppercase(); if (clever || ability === "yes"){ console.log("you beat him , go on way gamestop."); }else{ console.log("you aren't clever or @ chess, why did challenge troll game?"); } break; }; } </script> </head> <body> <button type="button" onclick = "myfunction();">game start</button> </body> </html>
when run code, .html, displays button doesn't when click it. able make button alert believe problem code not calling function, can please alert me if doing wrong.
there no function called myfunction(). want choosegame()
<button type="button" onclick="choosegame();">game start</button>
(also removed spacing around equal sign. isn't breaking it, not legal html).
Comments
Post a Comment