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