我正在通过串联将特定单词插入到句子中,但单词连续在一起,之间没有空格。
var adjective1 = + 'amazing';
var adjective2 = + 'fun';
var adjective3 = + 'entertaining';
var madLib = 'The Intro to JavaScript course is' + adjective1 + 'james and Julia are so' +
adjective2 + 'I cannot wait to work through the rest of this' + adjective3 + 'content!';
console.log(madLib);
最佳答案
只需添加空格
var madLib = 'The Intro to JavaScript course is ' + adjective1 + ' james and Julia are so' +
adjective2 + 'I cannot wait to work through the rest of this ' + adjective3 + ' content!';
变量赋值中的字符串之前也不应该有 +
。这将尝试将字符串转换为数字,并会产生 NaN
因为它们不是数字。
var adjective1 = 'amazing';
var adjective2 = 'fun';
var adjective3 = 'entertaining';
关于javascript - 如何在连接 JavaScript 句子时添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59795550/