← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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