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