انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Web: home
0. Lab tour1
1. HTML: the page's content7
2. CSS: the page's look6
3. JavaScript: the actions7
4. The project: the to-do list3
5. Pro CSS: shadows and movement5
6. Arrays and building the page with code3
7. Events and forms3
8. Objects and time3
9. Canvas: drawing and games3
10. The final project: the memory game3

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.

🌐 A card in the Console
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 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 lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Print your name in the Console.

👀 Show the solution
🌐 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 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
🌐 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 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
🌐 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 page in Robo Web
🖥️ The Console in Robo Web:
0
20

Result: 0, then 20

Finished the lesson? Mark it so your progress counts.