Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
Else statement in JavaScript not calculating properly

I'm very new to JavaScript and designing a very simple program to calculate the fine for returning books late to the library.

If 5 or less days late = 40p per day If 6 - 10 days late = 65p per day If over 10 days late = 80p

The else statement is returning the wrong amount? In the example totalThree should equal £8.80 for 11 days but result says £7.15?

const daysLate = 11;
const totalOne = daysLate * 0.40;
const totalTwo = daysLate * 0.65;
const totalThree = daysLate * 0.80;

if (daysLate <= 5) {
    console.log(`Your fine is £${totalOne}`)
} else if (daysLate >= 6 || daysLate <= 10) {
    console.log(`Your fine is £${totalTwo}`)
} else {
    console.log(`Your fine is £${totalThree}`)
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

(daysLate >= 6 || daysLate <= 10) is returning true becaues 11 >= 6. You need to change the || (or) operator into && (and) as shown below. This will check if both conditions are met.

else if (daysLate >= 6 && daysLate <= 10) {
    console.log(`Your fine is £${totalTwo}`);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!