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