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