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