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