If the user types negative numbers, show "enter a positive value".
If the user types an even number, show the next 3 even numbers.
If the user types an odd number, show the next 3 odd numbers.
You weren't specific at all, so I could only make an assumption of what you wanted.
function OpenPrompt(){ var value = prompt('Enter a positive integer number:'); var number = Number(value); if(value.=='' && Number?isInteger(number)){ alert('Next 3 '+(number%2===0:'even':'odd')+' numbers are, '+(number + 2)+', '+(number + 4)+'; '+(number + 6)); } else alert('You can only enter an integer number!'); }
<,DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Even - Odd</title> </head> <button onclick="OpenPrompt()">Open Prompt</button> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.