我刚刚了解了提示()命令;我知道提示()命令以字符串的形式返回用户输入。我在下面的程序中搞砸了,我在男性名称中输入了 per" dead" ohlin 。为什么这项工作却不引起任何问题?" per"死" ohlin ..."应该引起问题。解释器是否会通过在引号上放置逃生字符来自动解决此问题?
let nameOfTheKiller = prompt("Type in a male name.");
let nameOfTheVictim = prompt("Type in a female name.");
let nameOfDrug = prompt("Type in the name of a drug.");
let nameOfAlchoholicBeverage = prompt("Type in the name of an alchoholic beverage.");
let story = nameOfTheKiller
story += " went to a diner, met "
story += nameOfTheVictim + ", and asked her to hangout."
story += " She said yes, so " + nameOfTheKiller + " took her home. As soon as they arrived to "
story += nameOfTheKiller + " relax-location, " + nameOfTheKiller
story += " pulled out " + nameOfDrug + " and " + nameOfAlchoholicBeverage + ". "
story += nameOfTheKiller + " and " + nameOfTheVictim
story += " started using the party favors and got really high and drunk. The party favors gave "
story += nameOfTheKiller + " auditory halucinations that comanded him to kill "
story += nameOfTheVictim + ", so he did." ;
alert("We are done asking you questions. We are generating a story for you. The story will be finished, shortly.");
document.write(story) ;
prompt
不是 eval
-无论您传递给它什么,都将被解释为 string 。输入
Per "Dead" Ohlin
此行运行
let nameOfTheKiller = prompt("Type in a male name.");
就像做
let nameOfTheKiller = `Per "Dead" Ohlin`;
您输入的字符串中包含的任何字符也恰好是JavaScript中有效的字符串定界符,将被解释为这些文字字符( "
, '
,backtick),而不是定界器。<<<<<<<<<<<<<<<<<<<<<<<<<<<<