The number entered by the user must be:

  1. from 100 to 999
  2. the number is even
  3. not multiple 10
  4. a multiple of 100, not a multiple of 300
  5. 650 and 750 will return true

Here is my code, what's wrong?

 var num, res, message; num=prompt('enter a num'); num=+num; res=(num/650==0)&&(num/750==0)&&num>=100&&num<=999&&num%2==0&&num%10!==0&&num%100==0&&num%300!==0; message='Your number (true-even, false-odd): '+res; alert(message); 
  • division by 650 and 750 should return true? - Shezmu
  • 6
    you have mutually exclusive non-multiple of 10 and multiple of 100. because the number is a multiple of 100 times and 10 - Shezmu
  • 2
    I don’t understand the purpose of this part: (num / 650 == 0) && (num / 750 == 0). After all, when dividing a number by 650 it turns out to be 0, it is necessary that the number be zero. - Sleepy Panda
  • everything gives a fall (I don `t know how to do everything correctly (( - The Marafonskiy

1 answer 1

Insidious rules :)
999 will never return because of the second item, why include it?
Apparently the rule about multiplicity 100 overrides the rule about the prohibition of multiplicity 10, otherwise there is an error in the rules (anything that is a multiple of 100 is exactly a multiple of 10).


from 100 to 999

  1. 99 - false
  2. 1000 - false

the number is even

  1. 102 - true

not multiple 10

  1. 110 - false

a multiple of 100, not a multiple of 300

  1. 100 - true
  2. 300 - false

650 and 750 will return true

  1. 650 - true
  2. 750 - true

 let log = document.querySelector('#result'), input = document.querySelector('#input'), printResult = e => (log.style.color = msgType ? 'green' : 'red') && (log.innerHTML = msgType ? 'Passed :)' : 'Not passed!'), msgType = 0; function checkInput(e){ let value = this.value.trim(); msgType = 0; if(value === ''){ log.innerHTML = ''; return; } if(!/^\d+$/.test(value)) printResult(); value = +value; msgType = (value === 650 || value === 750) || ( (value >= 100 && value <= 999) && (value % 2 === 0) && ((value % 100 === 0 && value % 300 !== 0) || (value % 10 !== 0)) ); printResult(); } input.addEventListener('input', checkInput); 
 #input:focus{outline: none;} 
 <link href="tests/qunit/qunit-2.0.1.css" rel="stylesheet"/> <script src="tests/qunit/qunit-2.0.1.js"></script> <ul> <li>От 100 до 999</li> <li>Число четное</li> <li>Не кратное 10</li> <li>Кратно 100, не кратно 300</li> <li>650 и 750 вернет true</li> </ul> <input type='text' id='input' autofocus /> <br /> <span id='result'></span>