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

  • Home
  • SEARCH
  • 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 7613509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:10:23+00:00 2026-05-31T02:10:23+00:00

so basically, please check this code – Full code – <script type=text/javascript> $(document).ready(function() {

  • 0

so basically, please check this code –

Full code –

  <script type="text/javascript">

  $(document).ready(function() {
  var seasonLookup = [
      {startDay: 1, startMonth:1, endDay: 10, endMonth: 6, season:1},
      {startDay: 21, startMonth:9, endDay: 31, endMonth: 12, season:1},
      {startDay: 11, startMonth:6, endDay: 30, endMonth: 6, season:2},
      {startDay: 1, startMonth:9, endDay: 20, endMonth: 9, season:2},
      {startDay: 1, startMonth:7, endDay: 31, endMonth: 8, season:3},    
      ];

  var cars = $('#cars_input').val();

  var priceone = ($('#cars_input option[value="'+cars+'"]').attr('priceone'));

  var pricetwo = ($('#cars_input option[value="'+cars+'"]').attr('pricetwo'));

  var pricethree = ($('#cars_input option[value="'+cars+'"]').attr('pricethree'));

  var pricefour = ($('#cars_input option[value="'+cars+'"]').attr('pricefour'));

  var pricefive = ($('#cars_input option[value="'+cars+'"]').attr('pricefive'));

  var pricesix = ($('#cars_input option[value="'+cars+'"]').attr('pricesix'));

  var priceseven = ($('#cars_input option[value="'+cars+'"]').attr('priceseven'));

  var priceeight = ($('#cars_input option[value="'+cars+'"]').attr('priceeight'));   

  var pricenine = ($('#cars_input option[value="'+cars+'"]').attr('pricenine'));                                                                                                                                                                                                                                             

  var priceMatrix = {
      cars: {
          1: { t1: priceone, t2: pricetwo, t3: pricethree},
          2: { t1: pricefour, t2: pricefive, t3: pricesix},
          3: { t1: priceseven, t2: priceeight, t3: pricenine}
      }       
  };

  function getSeason(date){
      var day = date.getDate();
      var month = date.getMonth()+1;
      var year = date.getFullYear();
      for(var i=0;i<seasonLookup.length;i++){
          var s = seasonLookup[i];
          var startDate = new Date(year, s.startMonth-1,s.startDay);
          var endDate = new Date(year, s.endMonth-1,s.endDay);
          if(date >= startDate && date <= endDate)
              return s.season;
      }
      return null;
  }

  function getPrice(bike, season, days){
    var tier = "";
    if(days <=2)
      tier = "t1";
    else if(days <=7)    
        tier = "t2";
     else
         tier = "t3"
             console.log(days + ' days in season ' + season + ' at ' + priceMatrix[bike][season][tier] + '/day (' + tier + ')')
     return priceMatrix[bike][season][tier] * days;
  }

  function calculatePrice(startDate, endDate, bike)
  {
      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;
  }

  $('.recalc').change(function(){
      var startDate = new Date(parseInt($('#year_input').val(),10),parseInt($('#month_input').val(),10)-1,parseInt($('#day_input').val(),10) );
      var endDate = new Date(parseInt($('#yearr_input').val(),10),parseInt($('#monthr_input').val(),10)-1,parseInt($('#dayr_input').val(),10));
      var bike = $('#bike').val();

      var price = calculatePrice(startDate,endDate,bike);
      $('#car-price').val(price);

  });
  $('#cars_input').change();
  });


  </script>

What I’ve done there is assign a variables, and then I tried to add the variables to variable array called priceMatrix, but it’s not assigning somehow. I think that’s because I’m assigning variable as it’s done in jquery, could you please try help me fix the issue?

EDIT: JSFIDDLE Demo – http://jsfiddle.net/tSsvb/2/

  • 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-05-31T02:10:24+00:00Added an answer on May 31, 2026 at 2:10 am

    When you’re grabbing the data from the DOM, they’re strings not numbers. You must force the numeric type by using parseInt() or parseFloat()

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

Sidebar

Related Questions

yes, this is a homework-type question but could you please help me out? In
I have written this code to check for a particular string from a file.
I have this piece of code that basically checks if one or more files
Please check the code below: objDDLTable = HttpContext.Current.Cache[TestSet] as Hashtable; if (objDDLTable == null)
Can someone please tell me why this code is leaking? Instruments is showing several
This code basically fetches data from database and display it in a list along
please check the following code. $imagebaseurl = 'support/content_editor/uploads/$name'; The $imagebaseurl is a variable that
Basically my problem is with the page at http://wiki.diablocommunity.com/index.php?title=Tristram_Cathedral Please see the screen shots
basically i have (state, state code) pairs, that are subsets of country [USA] ->
Basically I want to run a script checking for the existence of a certain

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.