Answer to Question #270419 in HTML/JavaScript Web Application for prime

Question #270419

Passed test cases 1/4. Please solve it

Sample Input 1

200
3

Sample Output 1

570

Sample Input 2

180
1

Sample Output 2

180

These are just samples there are other test cases too.


let inputString = '';

let currentLine = 0;

process.stdin.on('data', inputStdin => {

    inputString += inputStdin;

});

process.stdin.on('end', _ => {

    inputString = inputString.trim().split('\n').map(string => {

        return string.trim();

    });

    main();    

});

function readLine() {

    return inputString[currentLine++];

}

function main() {

    const dayCharge = JSON.parse(readLine());

    const days = parseInt(readLine());

    let bill, discount;

    bill = dayCharge * days;

    if (days >= 2) {

      discount = 5;

      bill - (bill * discount) / 100;

    }

    if (days >= 5) {

      discount = 15;

      bill - (bill * discount) / 100;

    }

    console.log(`Total bill with the discont is ${bill}`);

}


1
Expert's answer
2021-11-25T07:53:38-0500

In main function conditions (if (days >= 2)) and (if (days >= 5)) are overlapped. Both conditions are satisfied if number of days "\\ge5"

function main() {

    const dayCharge = JSON.parse(readLine());

    const days = parseInt(readLine());

    let bill, discount;

    bill = dayCharge * days;

          if (days >= 2) and (days <= 5) {    \\correction
      
            discount = 5;
      
            bill - (bill * discount) / 100;
      
          }
      
          if (days >= 5) {
      
            discount = 15;
      
            bill - (bill * discount) / 100;
      
          }
      
          console.log(`Total bill with the discont is ${bill}`);
      
      }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS