sách gpt4 ai đã đi

JavaScript 提示()命令

In lại 作者:行者123 更新时间:2023-11-28 12:13:33 29 4
mua khóa gpt4 Nike

我刚刚了解了prompt()命令;我知道 Prompt() 命令以字符串的形式返回用户输入。我正在搞乱下面的程序,我输入了Per“Dead”Ohlin作为男性名字。为什么这有效并且没有引起任何问题? “Per“Dead”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) ;

1 Câu trả lời

prompt KHÔNG đánh giá - 您传递给它的任何内容都将被解释为字符串。输入

Per "Dead" Ohlin

当这条线运行时

let nameOfTheKiller = prompt("Type in a male name.");

就像在做

let nameOfTheKiller = `Per "Dead" Ohlin`;

您输入的字符串中包含的任何恰好也是 Javascript 中有效字符串分隔符的字符将被解释为那些文字字符 (", ' ,反引号),而不是作为分隔符。

关于JavaScript 提示()命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55173459/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com