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