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