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