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