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