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