Shenshen
05-23-2006, 12:02 AM
I'm trying to do a short script for a class. The script should generate two random numbers and ask the user what the sum of the two numbers is. I'm having some trouble making it work, this is what I have so far -- I'm new to scripting at all (I'm in a game design major but I'm a writer, so this is all strange to me!). Any help would be hugely, hugely appreciated. Thanks in advance!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Problem 2</title>
<script language="javascript" type="text/javascript">
var guess = 0
var target1 = 0;
var target2 = 0;
var correct = target1+target2
var msg = "";
target1 = Math.floor(Math.random() * 10) + 1;
target2 = Math.floor(Math.random() * 5) + 2;
guess = eval(Prompt("What is " target1 "plus" target2 "?", ""));
while (guess != correct){
guess = prompt ("What is " target1 "plus" target2 "?", "");
if (guess == correct){
alert ("Good job!");
} else {
alert ("Sorry, try again!");
} // end if
} // end while
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Problem 2</title>
<script language="javascript" type="text/javascript">
var guess = 0
var target1 = 0;
var target2 = 0;
var correct = target1+target2
var msg = "";
target1 = Math.floor(Math.random() * 10) + 1;
target2 = Math.floor(Math.random() * 5) + 2;
guess = eval(Prompt("What is " target1 "plus" target2 "?", ""));
while (guess != correct){
guess = prompt ("What is " target1 "plus" target2 "?", "");
if (guess == correct){
alert ("Good job!");
} else {
alert ("Sorry, try again!");
} // end if
} // end while
</script>
</head>
<body>
</body>
</html>