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