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