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