Sunday, 15 January 2012

Javascript Syntax error: missing ) after argument list: on col 61 -



Javascript Syntax error: missing ) after argument list: on col 61 -

okay here code, know how prepare this? won't run.

<!doctype html> <html> <head> <title>hiding game</title> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="proj3.css" /> </head> <body> <script type="text/javascript"> var counter = 0; document.writeln("<table>") document.writeln("<th>day</th>") document.writeln("<th>hiding place</th>") document.writeln("<th>explosion</th>") do{ counter = counter + 1 var hide = number(prompt("it day " + counter + ". hide (1, 2, 3, or 4)?")); var explosionlocation = math.floor(math.random() * 4) + 1; if (hide <1 || hide >4) { alert("that not valid choice.") } else { alert("hiding place " + explosionlocation + " has exploded!") if (hide !== explosionlocation) { alert("you have survived!") document.writeln("<tr><th>" + counter + "</th><td class='survived'>" + hide + "</td><td class='survived'>" + explosionlocation + "</td></tr>") } else { alert("you have died. survived total of " counter - 1 " days.") document.writeln("<tr><th>" + counter + "</th><td class='died'>" + hide + "</td><td class='survived'>" + explosionlocation + "</td></tr>"") document.writeln("<tr colspan='3'><td>"'survived ' + counter - 1 + ' days""</td></tr>") } } } while (explosionlocation !== hide) </script>

if can help appreciated. code supposed generate game user tries avoid 1 in 4 chance of dying.

this should bare minimum code running:

var counter = 0; document.writeln("<table>") document.writeln("<th>day</th>") document.writeln("<th>hiding place</th>") document.writeln("<th>explosion</th>") do{ counter = counter + 1 var hide = number(prompt("it day " + counter + ". hide (1, 2, 3, or 4)?")); var explosionlocation = math.floor(math.random() * 4) + 1; if (hide <1 || hide >4) { alert("that not valid choice.") } else { alert("hiding place " + explosionlocation + " has exploded!") if (hide !== explosionlocation) { alert("you have survived!") document.writeln("<tr><th>" + counter + "</th><td class='survived'>" + hide + "</td><td class='survived'>" + explosionlocation + "</td></tr>") } else { alert("you have died. survived total of " + (counter - 1) + " days.") document.writeln("<tr><th>" + counter + "</th><td class='died'>" + hide + "</td><td class='survived'>" + explosionlocation + "</td></tr>") document.writeln("<tr colspan='3'><td>survived " + (counter - 1) + " days</td></tr>") } } } while (explosionlocation !== hide)

the 3 key lines changed these:

alert("you have died. survived total of " + (counter - 1) + " days.") document.writeln("<tr><th>" + counter + "</th><td class='died'>" + hide + "</td><td class='survived'>" + explosionlocation + "</td></tr>") document.writeln("<tr colspan='3'><td>survived " + (counter - 1) + " days</td></tr>") }

a few quotes mismatched, , need place parenthesis around counter - 1 if you'd math on it. otherwise, javascript gets confused you're asking of when place - in middle of combining strings.

javascript

No comments:

Post a Comment