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