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