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