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