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