Front-end practice--javascript--functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.