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