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