JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
-
1.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 1;
console.log(x + y); (a) 4 (b) Error (c) 31 -
2.⚡ What number does this code print?
let score = 5;
score = score + 9;
score = score - 12;
console.log(score); -
3.⚡ What number does this code print?
let coins = 21;
coins = coins + 7;
coins = coins - 17;
console.log(coins); -
4.⚡ What number does this code print?
let a = 42;
let b = 21;
console.log(a - b); -
5.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) name (b) Hi, Kabir! (c) Hi, name! (d) Kabir -
6.⚡ What number does this code print?
let a = 29;
let b = 4;
console.log(a - b); -
7.⚡ What number does this code print?
let a = 12;
let b = 2;
console.log(a * b); - 8.⚡ What does JavaScript add to a web page? (a) only colours (b) the page title (c) actions and changes (d) the domain name
- 9.⚡ Which JavaScript word shows a pop-up box? (a) for (b) if (c) console.log() (d) alert()
-
10.⚡ What number does this code print?
let coins = 13;
coins = coins + 5;
coins = coins - 15;
console.log(coins); -
11.⚡ What does this code show?
let name = "Kabir";
alert("Well done, " + name + "!"); (a) Kabir (b) Well done, name! (c) Well done, Kabir! (d) name -
12.⚡ What does this code show?
let name = "Aman";
console.log("Hello, " + name + "!"); (a) Aman (b) Hello, name! (c) Hello, Aman! (d) name - 13.⚡ Which JavaScript word repeats code? (a) let (b) for (c) if (d) alert()
-
14.⚡ What does this code show?
let name = "Zoya";
console.log("Hello, " + name + "!"); (a) Hello, name! (b) name (c) Zoya (d) Hello, Zoya! -
15.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 8;
console.log(x + y); (a) Error (b) 58 (c) 13 - 16.⚡ Which JavaScript word runs code when true? (a) let (b) console.log() (c) if (d) for
-
17.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 5;
console.log(x + y); (a) Error (b) 8 (c) 35 -
18.⚡ What does this code show?
let name = "Riya";
console.log("Welcome, " + name + "!"); (a) Welcome, name! (b) Riya (c) name (d) Welcome, Riya! - 19.⚡ Which tag holds JavaScript in a page? (a) <js> (b) <code> (c) <script> (d) <style>
-
20.⚡ What number does this code print?
let score = 30;
score = score + 2;
score = score - 2;
console.log(score); - 21.⚡ Which JavaScript word makes a new variable? (a) let (b) console.log() (c) if (d) alert()
-
22.⚡ What number does this code print?
let marks = 10;
marks = marks + 16;
marks = marks - 26;
console.log(marks); -
23.⚡ What number does this code print?
let a = 12;
let b = 12;
console.log(a * b); -
24.⚡ What number does this code print?
let coins = 5;
coins = coins + 20;
coins = coins - 22;
console.log(coins); - 25.⚡ What does alert() show? (a) a table (b) a pop-up box (c) a picture (d) a new tab
-
26.⚡ What does this code show?
let name = "Kabir";
alert("Welcome, " + name + "!"); (a) Welcome, name! (b) Welcome, Kabir! (c) name (d) Kabir -
27.⚡ What number does this code print?
let runs = 11;
runs = runs + 19;
runs = runs - 1;
console.log(runs); -
28.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 8;
console.log(x + y); (a) 9 (b) Error (c) 18 -
29.⚡ What number does this code print?
let a = 46;
let b = 39;
console.log(a + b); -
30.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 5;
console.log(x + y); (a) 12 (b) Error (c) 75 -
31.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 9;
console.log(x + y); (a) 11 (b) 29 (c) Error -
32.⚡ What number does this code print?
let score = 28;
score = score + 15;
score = score - 40;
console.log(score); -
33.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 1;
console.log(x + y); (a) 7 (b) 61 (c) Error -
34.⚡ What number does this code print?
let a = 7;
let b = 33;
console.log(a + b); -
35.⚡ What number does this code print?
let marks = 24;
marks = marks + 15;
marks = marks - 32;
console.log(marks); - 36.⚡ Where does console.log() show its output? (a) on the printer (b) on the title bar (c) in the address bar (d) in the console
-
37.⚡ What number does this code print?
let a = 38;
let b = 6;
console.log(a - b); -
38.⚡ What number does this code print?
let a = 47;
let b = 26;
console.log(a - b); -
39.⚡ What number does this code print?
let a = 7;
let b = 10;
console.log(a + b); - 40.⚡ Which JavaScript word writes in the console? (a) alert() (b) let (c) if (d) console.log()
Answer key
- 31
- 2
- 11
- 21
- Hi, Kabir!
- 25
- 24
- actions and changes
- alert()
- 3
- Well done, Kabir!
- Hello, Aman!
- for
- Hello, Zoya!
- 58
- if
- 35
- Welcome, Riya!
- <script>
- 30
- let
- 0
- 144
- 3
- a pop-up box
- Welcome, Kabir!
- 29
- 18
- 85
- 75
- 29
- 3
- 61
- 40
- 7
- in the console
- 32
- 21
- 17
- console.log()
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids