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