← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 931 · 40 questions
TalentJR

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

Answer key

  1. .js
  2. 20
  3. Hi, Riya!
  4. 45
  5. alert()
  6. Well done, Meera!
  7. 13
  8. if
  9. Hello, Arjun!
  10. 43
  11. <script>
  12. actions and changes
  13. 8
  14. 14
  15. Hello, Riya!
  16. Hello, Aman!
  17. 29
  18. 16
  19. let
  20. 3
  21. 24
  22. for
  23. Hello, Zoya!
  24. 43
  25. 18
  26. 20
  27. Welcome, Arjun!
  28. in the console
  29. console.log()
  30. 72
  31. a pop-up box
  32. 19
  33. 12
  34. 7
  35. 51
  36. let
  37. 29
  38. 0
  39. 72
  40. 11

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids