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