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