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