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 8712789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:11:00+00:00 2026-06-13T05:11:00+00:00

Here is the assignment so it’s clear what I’m trying to do. Write a

  • 0

Here is the assignment so it’s clear what I’m trying to do.

Write a program that calculates the price of a hotel room based on three factors. First, how many will be in one room: 1-2, 3-4, or 5-6? No more than six are allowed in a room. Second, are the guests members of AAA? Third, do they want a room with a view? The rate is calculated as follows:

Basic room rate is:
1-2 people = $50/night
3-4 people = $60/night
5-6 people = $70/night
There is a discount for AAA members off of the basic room rate per night:
1-2 people = 15%
3-4 people = 10%
5-6 people = 5%
A room with a view costs 10% more per night after all other calculations are performed.

The program should prompt the user for all the inputs, perform the calculations and output the total cost per night. It is suggested to use at least some nested if/else structures to calculate the cost.

Debuggers like firebug and JSLint haven’t been any help and I suspect I’m just doing something completely wrong, though I haven’t had trouble with “nested if” logic assignments before. Regardless I am a complete and utter newby.

When I test by inputting 1 for numberOfGuests, N for tripleAStatus, and N for roomView, finalRate is returning as isNaN (I know this means not a number), and I can’t figure out why.

//Variable Declaration

var numberOfPeople;
var tripleAStatus;
var roomView;
var discountRate;
var roomRate;
var finalRate;
var discountPercent;

//Input

numberOfPeople = prompt("How many guests will their be? 6 Maximum.");


tripleAStatus = prompt("Are you a AAA Member? Y/N.");

roomView = prompt("Would you like your room to have a view?");



//Logic

if ((numberOfPeople <= 2) && (numberOfPeople > 0)) {
   roomRate = 50;
   discountPercent = .15;
} else if ((numberOfPeople <= 4) && (numberOfPeople > 2)) {
   roomRate = 60;
   discountPercent = .10;
} else if ((numberOfPeople <= 5) && (numberOfPeople > 4)) {
   roomRate = 70;
   discountPercent = .5;
} else {
   alert("Your number of guests must be at least 1 and no more than 6");
}

if (tripleAStatus = "Y") {
   discountRate = roomRate - (roomRate * discountRate);
} else if (tripleAStatus = "N") {
   discountRate = roomRate;
} else {
   alert("You need to answer with either Y or N");
}

if (roomView = "Y") {
   finalRate = (discountRate) + ((discountRate) * .10);
} else if (roomView = "N") {
   finalRate = discountRate;
} else {
   alert("You need to answer with either Y or N");
}

//Output

document.write("Total cost per night is " + "$" + finalRate);
  • 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-13T05:11:01+00:00Added an answer on June 13, 2026 at 5:11 am

    It looks like

    discountRate = roomRate - (roomRate * discountRate);
    

    Should read

    discountRate = roomRate - (roomRate * discountPercent);
    

    Which is why you’re getting NaN in finalRate; discountRate hasn’t been defined at this point, so your code actually reads discountRate = 1 - (1 * undefined).

    As other posters have mentioned, you also need to change your conditionals to use == or ===; = is an assignment operator, so rather than checking if tripleAStatus is "Y", you’re actually checking if "Y" evaluates to true (which it always will).

    tripleAStatus = 'N';
    if (tripleAStatus = 'Y') {
        // tripleAStatus is now "Y", and the code inside this if will always be executed
    }
    

    Working changes: http://jsfiddle.net/5ZVkE/

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

Sidebar

Related Questions

Here is the assignment verbatim: 1.) Write a Java program that is a TCP
So I'm trying to do my programming assignment, here it is: Write a C/C++
Here is my code for this simple assignment: Write the code that will read
The Java tutorials here mention that &= is an assignment operator but doesn't seem
I am trying to basically do 3 things at once here: overload the assignment
Doing some homework here (second assignment, still extremely green...). The object is to read
Can I optimize the class assignment here at all? I have to do this
Here is my code: /* Scott Landau Robot Lab Assignment 1 */ // Standard
I recently revisited the copy constructor, assignment operator, copy swap idom seen here: What
Here is the code in a function I'm trying to revise. This example works

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.