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