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