← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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