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