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