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