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