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