← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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