Variables and console.log
Section 3: JavaScript: the actionsLesson 3.2 · ⏱ 7 min
let makes a variable, and console.log writes in the Console, a place where the program writes to tell you what is happening.
JavaScript
let name = "Sara";
let age = 11;
console.log("My name is", name);
console.log("Next year I will be", age + 1);
🖥️ The Console in Robo Web:
My name is Sara Next year I will be 12
📌 Another example: a card in the Console
Variables of different kinds, and console.log prints them.
HTML
<p>Look at the Console 👇</p>
CSS
body { font-family: Tahoma, sans-serif; }
JavaScript
let name = "Mona";
let age = 10;
let likesCode = true;
console.log("Name:", name);
console.log("Age in 5 years:", age + 5);
console.log("Do you love coding?", likesCode);
🖥️ The page in Robo Web:

🖥️ The Console in Robo Web:
Name: Mona Age in 5 years: 15 Do you love coding? true
✍️ Practise
Variables.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
Print your name in the Console.
👀 Show the solution🙈 Hide the solution
HTML
<p>Console 👇</p>
CSS
body { font-family: Tahoma, sans-serif; }
JavaScript
let name = "Ali";
console.log(name);
🖥️ The page in Robo Web:

🖥️ The Console in Robo Web:
Ali
Result: Ali
Medium
Print the sum and the product of two numbers.
👀 Show the solution🙈 Hide the solution
HTML
<p>Console 👇</p>
CSS
body { font-family: Tahoma, sans-serif; }
JavaScript
let a = 6;
let b = 7;
console.log(a + b);
console.log(a * b);
🖥️ The page in Robo Web:

🖥️ The Console in Robo Web:
13 42
Result: 13, then 42
Hard
A variable that changes: the points are 0, then +10 twice.
👀 Show the solution🙈 Hide the solution
HTML
<p>Console 👇</p>
CSS
body { font-family: Tahoma, sans-serif; }
JavaScript
let score = 0;
console.log(score);
score = score + 10;
score = score + 10;
console.log(score);
🖥️ The page in Robo Web:

🖥️ The Console in Robo Web:
0 20
Result: 0, then 20

