Learn with Yasir

Share Your Feedback


๐Ÿงช Coding Exercises

๐ŸŸข Beginner Exercises

  1. โœ… Change Text Color on Button Click
  2. Create a paragraph with some text and a button. When the button is clicked, change the text color of the paragraph to blue.
    

    Requirements

    • Use `getElementById()` to access the paragraph.
    • Use JavaScript to change the style color property.

    Input

    <button onclick="changeColor()">Change Color</button>
    

    Expected Output

    # The paragraph text changes to blue when the button is clicked
    

    ๐Ÿ“š View Solution


  3. โœ… Change Font Size Dynamically
  4. Create a paragraph with some text and a button. When the button is clicked, increase the font size of the paragraph text.
    

    Requirements

    • Use `getElementById()` to access the paragraph.
    • Modify the `style.fontSize` property using JavaScript.

    Input

    <button onclick="increaseFont()">Increase Font</button>
    

    Expected Output

    # The paragraph font size increases when the button is clicked
    

    ๐Ÿ“š View Solution


  5. โœ… Change Background Color Randomly
  6. Create a button that, when clicked, changes the background color of the web page to a random color from a predefined list.
    

    Requirements

    • Use JavaScript's `Math.random()` to pick a color.
    • Update `document.body.style.backgroundColor`.

    Input

    <button onclick="randomBg()">Random Background</button>
    

    Expected Output

    # The background color of the page changes randomly each time the button is clicked
    

    ๐Ÿ“š View Solution


๐ŸŸก Intermediate Exercises

๐Ÿ”ด Advanced Exercises