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