#5: What is wrong with my code?


#1


https://www.codecademy.com/courses/learn-javascript/lessons/variables/exercises/string-interpolation?action=lesson_resume


The code works without the + operator but not with it.

Errors are:
Expected an identifier and instead saw ')'
Expected ')' but instead saw ';'
Missing semicolon

var favoriteAnimal = 'cat';
console.log('My favorite animal:' + favoriteAnimal +);

#2

You mean the last "+" added makes it go though

This should run pass.

console.log('My favorite animal:' + favoriteAnimal);

#3

Oh, now I get it! In the example there was a "+" before and after the variable but I guess the last one is unnecessary if the variable isn't followed but another string. Thanks!


#4

Yup. The "+" concatenates.

You're welcome.

Have fun coding! :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.