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