-1

when the HTML page loads, a prompt dialog box appears, which prompts the user to enter a number between 0 and 100. If the entered number is less than 50 - then an alert dialog box is displayed from message "unsatisfactory", if the number is between 50 and 70 - "satisfactory", from 71 to 87 - "good", from 88 to 100 - "excellent".

 a = +prompt('Введіть число 0-100');
if (a < 50) {
    alert('«unsatisfactory')
    
}
else if (51 < a < 70) {
    alert('satisfactory')
}


else if (a < 71 < 87) {
    alert('good')
}

else if (88 < a < 100) {
    alert('excellent')
}
opa
  • 1
  • 1
  • so what is the issue then? please update your question and provide a working example and the issue you are having/ – Dean Van Greunen Sep 08 '22 at 12:18
  • You can try these things out in the JavaScript debug console in your browser. Try setting `number` to something like 12 or 72 and see if `number === '0-50'` does what [you want it to do](https://stackoverflow.com/questions/6454198/check-if-a-value-is-within-a-range-of-numbers). – jarmod Sep 08 '22 at 12:23
  • Does this answer your question? [Check if a value is within a range of numbers](https://stackoverflow.com/questions/6454198/check-if-a-value-is-within-a-range-of-numbers) – jarmod Sep 08 '22 at 12:25
  • JS can't chain multiple `<` into a single equality like this, it will convert the first set e.g. `a < b` in `a < b < c` into a boolean, and then compare `c` against 1/0 for true/false. – DBS Sep 08 '22 at 12:51
  • Hi , Your condition checking is wrong , you suppose to check single at a time and use Operator for multiple Instead (51 < a < 70) Suppose to use else if(a>51 && a<70) then go on – Sethuraman Sep 08 '22 at 12:58

3 Answers3

0

check a = +prompt('Enter number 0-100');

if (a < 50) {
    alert('«unsatisfactory')
    
}
else if (51 < a < 70) {
    alert('satisfactory')
}


else if (a < 71 < 87) {
    alert('good')
}

else if (88 < a < 100) {
    alert('excellent')
}
opa
  • 1
  • 1
0
a = prompt('0-100');
alert(a > 87 ? 'Excellent': a > 70 ? 'Good': a>49 ?'Satisfactory':'unsatisfactory')

You can use a ternary operator which makes code read easier and simple to use it. Enjoy coding

Sethuraman
  • 654
  • 6
  • 15
0

The problem is you're supposing that javascript expressions are equal to mathematicals, but they're not.
If you want to check whether number is within range which mathematicaly could be written as 51 < a < 70 you have to split expression in two 51 < a && a < 70.
So your whole script should be rewrited into something like this:

 a = +prompt('Введіть число 0-100');
if (a < 50) {
    alert('«unsatisfactory')
    
}
else if (51 < a && a < 70) {
    alert('satisfactory')
}


else if (a < 71 && a < 87) {
    alert('good')
}

else if (88 < a && a < 100) {
    alert('excellent')
}
Jaood_xD
  • 808
  • 2
  • 4
  • 16