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