A program is a list of instructions the computer follows from top to bottom. We write it in the editor, and the result appears in the console.
To print text, write console.log followed by the text in quotes inside brackets. Change the text, then press Run:
console.log("Hello");
console.log("Good morning");Hello Good morning
;. Text must be inside quotes, otherwise you get an error:console.log(Good luck);
SyntaxError: missing ) after argument list
Comments
A line that starts with // is a comment: a note for you that the computer ignores. It is also handy for switching a line off without deleting it.
// Shopping list
console.log("Eggs");
// console.log("Apple");
console.log("Milk");Eggs Milk
Practice
Print Good night in the console.
Press Run to see the result. This program shows an error. Fix it so it prints Good luck.
Hint
Text needs quotes around it.console.log(Good luck);
Press Run to see the result. Turn the line that prints Fish into a comment so it is not printed.
console.log("Lion");
console.log("Fish");
console.log("Elephant");Press Run to see the result. Print your name on the first line and your city on the second. (The solution uses Mona and Cairo.)
Press Run to see the result. Print this shape on three lines:******
Press Run to see the result. Key points
console.log("text");prints text in the console.- Text goes inside quotes, and each line ends with
;. //starts a comment the computer ignores.