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