![](/img/trans.png)
[英]JavaScript:User enters numbers until he enters 0.Each numbers parity is determined and at the end,the total number of even and odd numbers is printed
[英]Writing a function that determines if both integers a user enters are odd numbers
您將如何編寫一個函數來確定用戶輸入的兩個數字是否都為奇數,並返回一個布爾值,如果兩個數字均為奇數,則返回true? 我已經知道如何編寫一個函數來確定用戶輸入的兩個數字是否相等。
那很簡單
numbersOdd(1,2); // return false
numbersOdd(14, 222); // return true;
function numbersOdd(n1, n2) {
return n1%2 === 1 && n2%2 === 1;
}
嘗試:
function bothOdd(num1, num2) { if (num1 % 2 == 1 && num2 % 2 == 1) { return true; } return false; } window.alert(bothOdd(1, 2)); window.alert(bothOdd(1, 1));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.