Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a function for JavaScript. I am creating a hotel booking websit

ID: 3596468 • Letter: I

Question

I need help with a function for JavaScript.

I am creating a hotel booking website and I need to create a function in javascript that will accept the users input for the date they are checking in, and then an user input for how many days they will stay.

This function will take in those to paramaters and then determine the number of full weekend visits that are inlcuded in the stay. (A full weekend visit consists of friday, saturday, and sunday) If all 3 days are not included in a row, then there would be no weekend stays.

I'm thinking there has to be some sort of loop that goes on to count the number of days. Any help is greatly apperciated.

Explanation / Answer

the following code does the required job

simple loop and count approach is used with the given conditions and returns it.

function weekends(inDate,Days){
   var count = 0;
   for(i=1;i<=Days;i++){
    var d = inDate.getDay();
    if((d==5)&&(Days-i>=2)){
     count++;
    }
    inDate.setDate(inDate.getDate()+1);
   }
   return count;
  }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote