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