【发布时间】:2016-07-08 01:39:03
【问题描述】:
我是新来的,这是我提出的第一个问题。这对你们中的一些人来说可能很容易,甚至都不好笑。我需要替换和/或删除一个字符串以使其适合。我试过在结尾处剪掉多条线,但我似乎无法让它为我工作。另外我正在使用记事本++
原字符串:
var num1;
var num2;
var answer;
num1 = prompt("Enter a number ");
num2 = prompt("Enter a number ");
document.write("You entered " + num1 + " and " + num2);
document.write("<br>");
answer = prompt("Enter the sum of " + num1 + " and " + num2);
document.write("You entered " + answer);
document.write("<br>");
num1 = parseInt(num1);
num2 = parseInt(num2);
var sum = num1 + num2;
document.write("The sum is " + sum);
<html>
<body>
</body>
</html>
我需要插入的字符串:
if (answer == sum) {
document.write("That is correct!");
} else {
document.write("That is not correct. The correct answer is " + sum);
}
【问题讨论】:
-
将
string that you need to insert复制到结束script标记上方时会发生什么? -
让我试试,我就放在上面,document.write("The sume is " + sum);
-
它的行为与没有我需要添加的字符串时相同。它并没有说明我添加的是对还是错。
-
您可以查看JSFiddle
-
你的代码和@Rajesh 的小提琴的区别似乎是
var sum = num1 + num2后面没有分号。另一方面,在 fiddle 的底部有这样一条消息:document.write is disallowed in JSFiddle environment and might break your fiddle.那么 fiddle 做了什么?
标签: javascript html notepad++