Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:38:28+00:00 2026-06-02T13:38:28+00:00

Basically, I need to fix this script, I tried to fix it, but it

  • 0

Basically, I need to fix this script, I tried to fix it, but it returns -1 of days.
You can see the new script here –

function calculatePrice(startDate, endDate, bike) {                           
    if(cars != "no") {
      console.log(startDate);
      console.log(endDate);
      var currentSeason = getSeason(startDate);
      var totalPrice = 0;
      var daysInSeason = 0;
      var currentDate = startDate;         
      var tierss = "";     
      var now = startDate;           
      var daye = 0;
      while(now <= endDate) {
        var season = getSeason(currentDate);
        daye++;
        now.setDate(now.getDate() + 1);    
      }
      if(daye <= 3) tierss = "t1";
      else if (daye <= 8) tierss = "t2";
      else tierss = "t3"                                    
      while (currentDate <= endDate) {                     
          var season = getSeason(currentDate);
          if (season != currentSeason) {
              totalPrice += getPrice(bike, currentSeason, daysInSeason, tierss);
              currentSeason = season;
              daysInSeason = 0;
          }
          daysInSeason++;
          console.log('days in season - ' + daysInSeason);
          currentDate.setDate(currentDate.getDate() + 1);
      }                                                
      totalPrice += getPrice(bike, currentSeason, daysInSeason, tierss);
      return totalPrice;
    }
    else {
      totalPrice = 0;
      return totalPrice;
    }
}

which returns -1 and this is the script which returns everything just fine –

function calculatePrice(startDate, endDate, bike) {                           
  if(cars != "no") {
    console.log(startDate);
    console.log(endDate);
    var currentSeason = getSeason(startDate);
    var totalPrice = 0;
    var daysInSeason = 0;
    var currentDate = startDate;
    while (currentDate <= endDate) {
        var season = getSeason(currentDate);
        if (season != currentSeason) {
            totalPrice += getPrice(bike, currentSeason, daysInSeason);
            currentSeason = season;
            daysInSeason = 0;
        }
        daysInSeason++;
        currentDate.setDate(currentDate.getDate() + 1);
    }
    totalPrice += getPrice(bike, currentSeason, daysInSeason);
    return totalPrice;
  }
  else {
    totalPrice = 0;
    return totalPrice;
  }
}

Why I need to edit the script? Simply, because it returns days in current season, but I need to inclue in totalPrice total days and days in current season. Or another possibility is that I need to include the tier in getprice, as shown above, both should work.

Hope to hear help :)!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:38:38+00:00Added an answer on June 2, 2026 at 1:38 pm

    if “now” and “startDate” are objects, then every time you call

    now.setDate(something)

    you also change startDate… because now and startDate are pointers that point to the same object.

    I’m not sure if that’s causing your error because I don’t see where you use startDate… but it could be changing it in the caller, for example.

    edit: yes that is your problem, currentDate, now, and startDate all point to the same date object — so your second while loop never executes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this on my own but couldn't get it to work right. Basically
i have this template code: <script type=text/javascript> $(function(){ //submit new messages when the user
I have been trying for hours to fix this code, I can't see what's
This should be quite simple but I can`t fix it :/ I am using
basically need to change the value that - admin_url() returns any idea?
I basically need to show a wait window to the user. For this i
I basically need to know how to import SQL code into Access. I've tried
I basically need to check if there is an easier way to do this
Basically this works fine: >>> x,y = x=y.split(=) >>> print x x But this
I'm trying to fix a dialog. The sticky property sticks it, but I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.