← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. in the console
  2. Welcome, Kabir!
  3. let
  4. 28
  5. 9
  6. alert()
  7. for
  8. 18
  9. Hi, Arjun!
  10. Hello, Zoya!
  11. 12
  12. 12
  13. Hi, Arjun!
  14. 14
  15. 11
  16. 9
  17. let
  18. 85
  19. 58
  20. 22
  21. Welcome, Kabir!
  22. Well done, Kabir!
  23. 14
  24. 9
  25. 40
  26. 50
  27. 23
  28. 33
  29. 51
  30. 24
  31. 23
  32. 17
  33. a pop-up box
  34. <script>
  35. 50
  36. 14
  37. 8
  38. 25
  39. Hi, Kabir!
  40. 52

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