Write a function called \"largerNum\" using function expression notation with th
ID: 3786601 • Letter: W
Question
Write a function called "largerNum" using function expression notation with the following parameters & return value: Any whole number (ie: 2, 567, 3947, 4, etc.) or string representing a whole number (ie: "25 65 95", etc). Any whole number (ie: 2, 567, 3947, 4, etc) or string representing a whole number (ie: "25", 65 "95", etc). Return value: The larger of the two numbers (number) or NaN if either num1 or num2 cannot be converted to a number (ie: abc", etc) For example, if num1 is "56" and num2 is 33, the function will return 56 (because 56 is larger than 33. Similarly, if num1 is 95 and num2 is "a", the function will return NaN (because "a" cannot be converted to a number) .Explanation / Answer
Here is the code for you:
function largeNum(num1, num2)
{
var num3 = Number(num1) > Number(num2) ? Number(num1) : Number(num2);
alert(num3);
return num3;
}
largeNum("145", "22");
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.