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