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