Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

Interactive Calculator Using Vite and Flexbox

vite
Vishakh Sandwar•160
@VSandwar74
A solution to the Tip calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


There's this bug where the console doesn't log the tips properly which results in sometimes the tip value resulting in 0, even when a tip button is pressed, here's a snippet of the code.

const keys = document.querySelector('.tips')
console.log(keys)

"change click".split(" ").forEach(function(e){
  keys.addEventListener(e, e => {
    let id = e.target.id
    if (id === "custom") {
      tip = Number(e.target.value)/100
    } else {
      tip = Number(id)
    }
    console.log(tip)
    output()
  })
});

and the html

        <div class="percent">
          <h4>Select Tip %</h4>
          <div class="tips">
            <button class="tip" data-action="5%" id="0.05">
              <h2>5%</h2>
            </button>
            <button class="tip" data-action="10%" id="0.1">
              <h2>10%</h2>
            </button>
            <button class="tip" data-action="15%" id="0.15">
              <h2>15%</h2>
            </button>
            <button class="tip" data-action="25%" id="0.25">
              <h2>25%</h2>
            </button>
            <button class="tip" data-action="50%" id="0.5">
              <h2>50%</h2>
            </button>
            <input class="tip" id="custom" type="percent" placeholder="Custom"/>
          </div>
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Vishakh Sandwar's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License