This question already has answers here:
Joining two strings with a comma and space between them
                            
                                (8个答案)
                            
                    
                在4个月前关闭。
        

    

我将带有连接词的特定单词插入句子中,但是单词a连在一起,并且它们之间没有空格。

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';

10-07 21:11