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