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