I'm just starting out here but I've got these two sections of JS code. The first block is an example from a book that I copied and pasted, the second block is one that I typed out and is (in my eyes) identical to the first block. However when I run the code, the second block (the one I typed) just doesn't work. I've looked at each character and can't find out why.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 2, Question 2</title>
</head>
<body>
<script>
var firstNumber = parseFloat(prompt("Enter the first number",""));
var secondNumber = parseFloat(prompt("Enter the second number",""));
var theTotal = firstNumber + secondNumber;
document.write(first number + " added to " + secondNumber + " equals " + theTotal);
</script>
</body>
</html>
答案 0 :(得分:3)
There is a space in first number.
This:
document.write(first number + " added to " + secondNumber + " equals " + theTotal);
should be:
document.write(firstNumber + " added to " + secondNumber + " equals " + theTotal);