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