Use JavaScript code to write out a function: Implement a large integer that pops up after passing in a two integer.
Task decomposition:
The first step: Write code to complete the definition of a function.
Step two: Let's add the control statement in the function body and complete the function function.
提示:再想一想,两个整数比较有三种情况,大于,等于或小于,所以我们需要控制语句判断(if...elseif)。
The third step: Write a good function, we can call the function arbitrarily. Implement two sets of values by function call, and return a larger value.
Code:
<! DOCTYPE html><html ><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " /><title>Function</title><script type="Text/javascript">//define Functions function Compare(x, y)//Functional body, judging three cases of two integer comparisons { if(x>y) {returnx;}Else if(x<y) {returnY;}Else if(x===y) {returnx| | Y;} }//Call function, implement the following two sets of numbers, return a larger value. document.write (The larger values for 5 and 4 are: "+compare (5,4)+"<br>"); document.write (The larger values for 6 and 3 are: "+compare (6,3)+"<br>"); document.write (The larger values for 4 and 4 are: "+compare (4,4)+"<br>");</script></head><body></body></html>
Demo Result:
Front-end practice--javascript--function