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