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