"foo") and a variable (
foo). I've explained that strings are surrounded by quotes while variables are not, but this is still one of the most common mistakes I see. For example, a programming task could be:
Create a prompt for a persons first and last names, and then print out a greeting (stored in a variable) followed by the name (last name, first name).
and a student will write the following code:
var greeting = "Hello "; var first_name = prompt("What's your first name?"); var last_name = prompt("What's your last name?"); var reply = greeting+" "+last_name+", "+first_name; console.log("reply"); // <-- Here's the problem
I typically see this issue when a student is trying to output information, either to the console or set a GUI element to have that text content. I also see it occasionally in other contexts, such as conditional statements.
What can I do to help students better avoid this mistake?