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