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.⚡ Which JavaScript word runs code when true? (a) for (b) console.log() (c) if (d) let
- 2.⚡ Which JavaScript word shows a pop-up box? (a) if (b) alert() (c) console.log() (d) let
-
3.⚡ What does this code show?
let name = "Meera";
alert("Hi, " + name + "!"); (a) name (b) Hi, Meera! (c) Hi, name! (d) Meera - 4.⚡ Which JavaScript word repeats code? (a) console.log() (b) alert() (c) for (d) if
- 5.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <code> (c) <style> (d) <js>
-
6.⚡ What number does this code print?
let apples = 24;
apples = apples + 4;
apples = apples - 6;
console.log(apples); - 7.⚡ Where does console.log() show its output? (a) on the title bar (b) in the address bar (c) in the console (d) on the printer
-
8.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 6;
console.log(x + y); (a) Error (b) 16 (c) 7 -
9.⚡ What does this code show?
let name = "Riya";
console.log("Hi, " + name + "!"); (a) Hi, Riya! (b) name (c) Riya (d) Hi, name! -
10.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 7;
console.log(x + y); (a) 15 (b) Error (c) 87 -
11.⚡ What number does this code print?
let a = 22;
let b = 1;
console.log(a + b); -
12.⚡ What number does this code print?
let a = 4;
let b = 7;
console.log(a * b); -
13.⚡ What number does this code print?
let a = 8;
let b = 8;
console.log(a * b); -
14.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 2;
console.log(x + y); (a) Error (b) 32 (c) 5 - 15.⚡ Which word makes a new variable? (a) give (b) make (c) let (d) put
- 16.⚡ Which JavaScript word writes in the console? (a) for (b) alert() (c) console.log() (d) if
-
17.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 1;
console.log(x + y); (a) Error (b) 81 (c) 9 -
18.⚡ What number does this code print?
let a = 35;
let b = 17;
console.log(a + b); -
19.⚡ What number does this code print?
let a = 26;
let b = 36;
console.log(a + b); -
20.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 9;
console.log(x + y); (a) Error (b) 19 (c) 10 -
21.⚡ What number does this code print?
let score = 26;
score = score + 2;
score = score - 15;
console.log(score); -
22.⚡ What does this code print? (Look at the quotes!)
let x = "3";
let y = 6;
console.log(x + y); (a) 36 (b) Error (c) 9 - 23.⚡ What does alert() show? (a) a new tab (b) a pop-up box (c) a picture (d) a table
-
24.⚡ What number does this code print?
let apples = 15;
apples = apples + 15;
apples = apples - 9;
console.log(apples); -
25.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 2;
console.log(x + y); (a) Error (b) 72 (c) 9 -
26.⚡ What does this code show?
let name = "Kabir";
alert("Welcome, " + name + "!"); (a) Welcome, name! (b) Kabir (c) Welcome, Kabir! (d) name -
27.⚡ What number does this code print?
let a = 27;
let b = 27;
console.log(a - b); -
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 does this code show?
let name = "Zoya";
console.log("Hello, " + name + "!"); (a) Hello, name! (b) Zoya (c) name (d) Hello, Zoya! -
30.⚡ What number does this code print?
let a = 12;
let b = 8;
console.log(a * b); -
31.⚡ 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 -
32.⚡ What does this code show?
let name = "Aman";
alert("Hello, " + name + "!"); (a) Hello, name! (b) Aman (c) name (d) Hello, Aman! -
33.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 3;
console.log(x + y); (a) Error (b) 63 (c) 9 -
34.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 3;
console.log(x + y); (a) Error (b) 7 (c) 43 -
35.⚡ What number does this code print?
let a = 2;
let b = 2;
console.log(a * b); -
36.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 1;
console.log(x + y); (a) Error (b) 5 (c) 41 -
37.⚡ What number does this code print?
let score = 25;
score = score + 10;
score = score - 25;
console.log(score); -
38.⚡ What number does this code print?
let a = 36;
let b = 6;
console.log(a + b); -
39.⚡ What number does this code print?
let score = 20;
score = score + 6;
score = score - 2;
console.log(score); -
40.⚡ What does this code show?
let name = "Riya";
console.log("Welcome, " + name + "!"); (a) Riya (b) Welcome, Riya! (c) name (d) Welcome, name!
Answer key
- if
- alert()
- Hi, Meera!
- for
- <script>
- 22
- in the console
- 16
- Hi, Riya!
- 87
- 23
- 28
- 64
- 32
- let
- console.log()
- 81
- 52
- 62
- 19
- 13
- 36
- a pop-up box
- 21
- 72
- Welcome, Kabir!
- 0
- 18
- Hello, Zoya!
- 96
- 58
- Hello, Aman!
- 63
- 43
- 4
- 41
- 10
- 42
- 24
- Welcome, Riya!
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids