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