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