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