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