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