我正在尝试进行一些有点不同路线修改的JavaScript对话,到目前为止我正在使用它:
JavaScript的:
alert("Hello\nFriend... Isnt this creepy?");
alert("Im sorry this is weird isnt it?\nMy name is MAX");
alert("MAX stands for Multipurpose AI Xample\n Sorry for my rude introduction, whats your name?");
alert("AH! A great name for such a lad or lass as your self...");
编辑:我想要一种方式让他们输入名称,然后我可以在整个代码中使用/引用名称
答案 0 :(得分:0)
var username = prompt('MAX stands for Multipurpose AI Xample. Sorry for my rude introduction, what is your name?');
alert('AH! ' + username + ' is a great name for such a lad or lass as yourself...');
只要您的“申请”只是alert
或prompt
的持续组合,username
变量将在稍后继续提供,例如
alert('I hope you are well today, ' + username + '!');
答案 1 :(得分:0)
Learn Javascript first. 如果要保存此人的姓名,请将其另存为变量。 如果您想稍后引用该人的姓名,请添加加号以组合变量和字符串
ex)"hello "+name+"!" == "hello kevin!" //where name="kevin"
var name=prompt("what is your name?","");//javascript will wait until you click enter. then the variable name will be set to whatever you inputed
alert("hello "+name+"! thats a great name!")//say hello!