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