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