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