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