← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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