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