+ 1

How to get code to work

A store is offering a tiered discounts based on the purchase total. 5000 and above => 50% 3000-4999 => 30% 1000-2999 => 10% 1-999 => 0% Write a program that takes the total price as input and outputs the corresponding discount to the console.

30th Nov 2020, 1:53 AM
Emmanuel Riano
Emmanuel Riano - avatar
5 Respuestas
+ 2
Fix your conditions. You need to use correct comparison operators on both sides of && to achieve the "between" condition. Like this: if (x >= 0 && x < 1000)
30th Nov 2020, 2:02 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Appreciate it Santa.
30th Nov 2020, 2:09 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
function main() { var totalPrice = parseInt(readLine(), 10) if (totalPrice >= 5000 ){ console.log("50%"); } else if (totalPrice !== 4999 && 3000){ console.log("30%"); } else if (totalPrice >= 1000 && 2999){ console.log("10%"); } if (totalPrice <= 999 && 1){ console.log("0%"); }}
30th Nov 2020, 1:53 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
Thats my code but i cant get all values to output correctly
30th Nov 2020, 1:54 AM
Emmanuel Riano
Emmanuel Riano - avatar
0
Ive tried almost every combination to get the code to work. What am i doing wrong?
30th Nov 2020, 1:56 AM
Emmanuel Riano
Emmanuel Riano - avatar