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