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