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