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