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