← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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