← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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