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