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