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