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