← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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