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