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