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