Hi guys, I was making a text based game in javascript..
Here it is:
<!doctype html>
<script type="text/javascript">
//Experimental Code - Text Based RPG
function error() {
alert(+choice+ "is not a recognised command")
maingame()
}
function maingame() {
choice = prompt('You find yourself in a dark room...do you\n[1]Eat cheese\n[2]Do stuff')
if (choice==2) {
next()
} else {
error()
}
}
</script>
<body onload="javascript: maingame()">
</html>
Ok. And here is the faulty part of the code (if you could not find it above)
function error() {
alert(+choice+ "is not a recognised command")
maingame()
}
It should give an alert box returning "foo is not a recognised command." but instead i get "NaNis is not a recognised command"
What am I doing wrong!?