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