ȨÆäÀÌÁöÁ¦ÀÛ±³½Ç
ȨÆäÀÌÁö Á¦ÀÛ±âÃÊ
±âº»Å±×
ÅÂ±×ÆÁ¸ðÀ½
ű×ÀÚ·á¹æ
Æ÷Åä¼¥°ÁÂ
À¥.°ü·Ã°ÁÂ
PHP°ÁÂ
PHPÆÁ
HTML.CSS
JAVASCRIPT
ASP
JSP
PHP½ÉÈ
C.C++
Ç÷¡½Ã.ActionScript
ÀÚÀ¯°Ô½ÃÆÇ
Áú¹®°Ô½ÃÆÇ
À¯¸Ó°Ô½ÃÆÇ
¿À¶ô½Ç
Tel. 042-353-2371
ÆòÀÏ ¿ÀÀü 9½Ã ~ ¿ÀÈÄ 7½Ã
±â¾÷ÀºÇà
010-8649-6758
¿¹±ÝÁÖ:Á¦ÁÖ»ç¶û(¼ÛÁø¾Æ)
JAVASCRIPT
Ȩ > ȨÆäÀÌÁöÁ¦ÀÛ±³½Ç > JAVASCRIPT
ÀÛ¼ºÀÚ
freewebkorea
Ä«Å×°í¸®
JavaScript
Tutorial
Object
ºñ¹Ð¹øÈ£
Á¦¸ñ
<H2>Math Object</H2> <P class=mtext>Math object´Â Math¶ó´Â ±ÛÀÚ¸¸ ºÁµµ ¾Ë ¼ö ÀÖµíÀÌ ¼öÇÐ(Mathemetics)¿¡ »ç¿ëµÇ´Â Property¿Í Method µéÀ» ´Ù·ç´Â Object°¡ µÇ°Ú½À´Ï´Ù. »ç½Ç ÀúÀÇ °æ¿ì¿¡´Â ¾Æ·¡ Ç¥¿¡ ÀÖ´Â Propertyµé Áß¿¡ PI ¸¦ Á¦¿ÜÇÑ ³ª¸ÓÁö µéÀº ½ÇÇàÇØ º» ÀûÀº À־ »ç¿ëÇØ º»ÀûÀº ´Ü ÇÑ ¹øµµ ¾ø±¸¿ä. µÎ ¹øÂ° Ç¥ÀÇ Method Áß¿¡¼´Â round(), ceil(), floor(), random(), max(), min() ÀÌ·¸°Ô 6°³ À̿ܿ¡´Â ½ÇÁ¦·Î »ç¿ëÇØ º¸Áö ¾Ê¾Ò½À´Ï´Ù. ±×·¸Áö¸¸ ÀÌ·± Property³ª Method°¡ ÇÊ¿äÇÑ »ç¶÷¿¡°Ô´Â ²À ÀÖ¾î¾ß µÇ´Â °Í µéÀ̰ÚÁÒ. º°·Î »ç¿ëÇØ º¸Áö ¾ÊÀº °Í µéÀ̶ó ÀÌ·¸°Ô °Á·Π²Ù¹Ì·Á´Ù º¸´Ï NetScape, W3C, MSDN, ECMA µîÀ» µÚÁ®¼ Á¤È®¼ºÀ» ±âÇß½À´Ï´Ù. ±×·¯°í º¸´Ï ÀÌ ÆäÀÌÁö´Â °Á¶ó±â º¸´Ù Á¦ ½º½º·Î °øºÎ¸¦ ÇÑ ¼ÀÀ̷২ä...^^<BR><BR><B>*** JavaScript ´ë¼Ò¹®ÀÚ¸¦ Á¤È®È÷ ±¸ºÐÇÑ´Ù´Â »ç½ÇÀ» Ç×»ó ÀØÀ¸¸é ¾È µÇ°Ú½À´Ï´Ù...</B></P> <TABLE class=attributeTbl cellSpacing=2 cellPadding=0 border=0> <CAPTION class=general><B>NN</B> : <B>N</B>etscape <B>N</B>avigator, <B>IE</B> : <B>I</B>nternet <B>E</B>xplorer (Property¿Í Method¸¦ ó¸®ÇÏ´Â ÃÖ¼Ò ºê¶ó¿ìÀú ¹öÀü)</CAPTION> <TBODY> <TR> <TD class=titleCell colSpan=4>Math Object Properties</TD></TR> <COLGROUP> <COL class=syntaxLeftCell width="15%"> <COL class=syntaxRightCell> <COL class=syntaxRightCell style="TEXT-ALIGN: center" span=2> <TBODY> <TR class=syntaxLeftCell> <TD>Properties</TD> <TD align=middle>¼³ ¸í</TD> <TD width="4%">NN</TD> <TD width="4%">IE </TD></TR> <TR> <TD>E</TD> <TD>ÀÚ¿¬ LOGÀÇ ¹Ø(base) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LN2</TD> <TD>2ÀÇ ÀÚ¿¬ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LN10</TD> <TD>10ÀÇ ÀÚ¿¬ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LOG2E</TD> <TD>¹Ø(base)ÀÌ 2ÀÎ EÀÇ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LOG10E</TD> <TD>¹Ø(base)ÀÌ 10ÀÎ EÀÇ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>PI</TD> <TD>PI(¿øÁÖÀ²) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>SQRT1_2</TD> <TD>1 / 2 Á¦°ö±Ù return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>SQRT2</TD> <TD>2 Á¦°ö±Ù return</TD> <TD>2.0</TD> <TD>3.0</TD></TR></TBODY></TABLE><BR><BR><!-- ÀÔ·Â pre ½ÃÀÛ --><B class=pos>Math Object Property ¿¹Á¦</B> <PRE class=input id=math_properties><html> <head> <title>Math °ü·Ã Properties</title> <script type="text/javascript"> <!-- document.write("Math.<b>E</b> = " + Math.E +"<br>") document.write("Math.<b>LN2</b> = " + Math.LN2 +"<br>") document.write("Math.<b>LN10</b> = " + Math.LN10 +"<br>") document.write("Math.<b>LOG2E</b> = " + Math.LOG2E +"<br>") document.write("Math.<b>LOG10E</b> = " + Math.LOG10E +"<br>") document.write("Math.<b>PI</b> = " + Math.PI +"<br>") document.write("Math.<b>SQRT2</b> = " + Math.SQRT2 +"<br>") document.write("Math.<b>SQRT1_2</b> = " + Math.SQRT1_2 ) // --> </script> </head> <body> </body> </html> </PRE><!-- ÀÔ·Â pre ³¡--><A href="javascript:copy2Clipboard(math_properties);open_window('../../include/code_executor.asp');"><IMG alt="ÄÚµå ½ÇÇà Çϱâ" src="http://www.cadvance.org/doc/images/icon/exec_button.gif" border=0></A><BR><BR> <HR class=grayHr> <BR><B>Math ObjectÀÇ Method</B> <P class=mtext>¾Æ·¡ÀÇ Method Áß¿¡ random(), round(), ceil(), floor(), max(), min() µîÀº ¾î´À ºÐ¾ß³ª ¾µ ¸ð°¡ ¸¹Àº MethodÀ̹ǷΠÀß ¾Ë¾Æ µÎ¸é À¯¿ëÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖÁ®...</P> <TABLE class=attributeTbl cellSpacing=2 cellPadding=0 border=0> <CAPTION class=general><B>NN</B> : <B>N</B>etscape <B>N</B>avigator, <B>IE</B> : <B>I</B>nternet <B>E</B>xplorer (Property¿Í Method¸¦ ó¸®ÇÏ´Â ÃÖ¼Ò ºê¶ó¿ìÀú ¹öÀü)</CAPTION> <TBODY> <TR> <TD class=titleCell colSpan=4>Math Object Methods</TD></TR> <COLGROUP> <COL class=syntaxLeftCell width="15%"> <COL class=syntaxRightCell> <COL class=syntaxRightCell style="TEXT-ALIGN: center" span=2> <TBODY> <TR class=syntaxLeftCell> <TD>Methods</TD> <TD align=middle>¼³ ¸í</TD> <TD width="4%">NN</TD> <TD width="4%">IE</TD></TR> <TR> <TD>abs(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ Àý´ë°ª(absolute Value) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>acos(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ arccosine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>asin(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ arcsine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>atan(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ arctangent °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>atan2(<I><FONT color=#941919>y,x</FONT></I>)</TD> <TD>X Ãà°ú ¾î¶² ÁÂÇ¥(x,y)°¡ ÀÌ·ç´Â °¢µµ(-pi ~ pi »çÀÌÀÇ radian °ª) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>ceil(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> °¡ ¼Ò¼öÀÏ °æ¿ì ¹«Á¶°Ç ¹Ý¿Ã¸² ¶Ç´Â Á¤¼öÀ̸é <I><FONT color=#941919>x</FONT></I> °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>cos(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ cosine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>exp(<I><FONT color=#941919>x</FONT></I>)</TD> <TD>ÀÚ¿¬ LOG EÀÇ Áö¼ö (ò¦â¦ : exponent) <I><FONT color=#941919>x</FONT></I> °ª (E<SUP>x</SUP> :E ÀÇ <I><FONT color=#941919>x</FONT></I> ã« ) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>floor(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> °¡ ¼Ò¼öÀÏ °æ¿ì ¹«Á¶°Ç ¹Ý³»¸²(Àý»ç) ¶Ç´Â Á¤¼öÀ̸é x °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>log(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ ÀÚ¿¬ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>max(<I><FONT color=#941919>x,y</FONT></I>)</TD> <TD><I><FONT color=#941919>x, y</FONT></I> Áß¿¡¼ Å« °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>min(<I><FONT color=#941919>x,y</FONT></I>)</TD> <TD><I><FONT color=#941919>x, y</FONT></I> Áß¿¡¼ ÀÛÀº °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>pow(<I><FONT color=#941919>x,y</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ <I><FONT color=#941919>y</FONT></I> ½Â(ã«) °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>random()</TD> <TD>0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>round(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ ¹Ý¿Ã¸² °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>sin(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ sine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>sqrt(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ Á¦°ö±Ù °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>tan(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ tangent °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR></TBODY></TABLE><BR><BR><!-- ÀÔ·Â pre ½ÃÀÛ --><B class=pos>Math Object Method ¿¹Á¦</B> <PRE class=input id=math_methods><html> <head> <title>Math °ü·Ã Methods</title> <script type="text/javascript"> <!-- document.write("-3.5ÀÇ Àý´ë°ªÀº : " + Math.<B>abs</B>(-3.5) + "<br />") document.write("PIÀÇ sine °ªÀº : " + Math.<B>sin</B>(Math.PI/2) + "<br />") document.write("PIÀÇ cosine °ªÀº : " + Math.<B>cos</B>(Math.PI/2) + "<br />") document.write("PIÀÇ tangent °ªÀº : " + Math.<B>tan</B>(Math.PI/2) + "<br />") document.write("0.5ÀÇ arcsine °ªÀº : " + Math.<B>asin</B>(0.5) + "<br />") document.write("0.5ÀÇ arccosine °ªÀº : " + Math.<B>acos</B>(0.5) + "<br />") document.write("0.5ÀÇ arctangent °ªÀº : " + Math.<B>atan</B>(0.5) + "<br />") document.write("ÁÂÇ¥ (3, 5)¿Í X ÃàÀÇ °¢µµ(radian)´Â : " + Math.<B>atan2</B>(3,5) + "<br />") document.write("ÀÚ¿¬ LOG EÀÇ 10½ÂÀº : " + Math.<B>exp</B>(10) + "<br />") document.write("4.9ÀÇ ¹«Á¶°Ç ¹Ý³»¸² °ªÀº : " + Math.<B>floor</B>(4.9) + "<br />") document.write("4.1ÀÇ ¹«Á¶°Ç ¹Ý¿Ã¸² °ªÀº : " + Math.<B>ceil</B>(4.1) + "<br />") document.write("10ÀÇ ÀÚ¿¬ LOG °ªÀº : " + Math.<B>log</B>(10) + "<br />") document.write("3°ú 5Áß¿¡ ´õ Å« ¼ö´Â : " + Math.<B>max</B>(3,5) + "<br />") document.write("3°ú 5Áß¿¡ ´õ ÀÛÀº ¼ö´Â : " + Math.<B>min</B>(3,5) + "<br />") document.write("2ÀÇ 3½Â(2<sup>3</sup>)Àº : " + Math.<B>pow</B>(2,3) + "<br />") document.write("0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö´Â ¸Ö±î? : " + Math.<B>random</B>() + "<br />") document.write("4.4999ÀÇ ¹Ý¿Ã¸² °ªÀº : " + Math.<B>round</B>(4.4999) + "<br />") document.write("2ÀÇ Á¦°ö±Ù °ªÀº : " + Math.<B>sqrt</B>(2) + "<br />") document.write("0 ~ 100 »çÀÌÀÇ ÀÓÀÇÀÇ Á¤¼ö´Â ¸Ö±î? : " + Math.<B>round</B>(Math.<B>random</B>() * 100)) <FONT color=#444400>// Math.random() ÀÇ °æ¿ì´Â '½ÇÇà °á°ú º¸±â' ´ÜÃ߸¦ ´©¸¦ ¶§ ¸¶´Ù ´Þ¶óÁý´Ï´Ù.</FONT> // --> </script> </head> <body> </body> </html> </PRE><!-- ÀÔ·Â pre ³¡--><A href="javascript:copy2Clipboard(math_methods);open_window('../../include/code_executor.asp');"><IMG alt="ÄÚµå ½ÇÇà Çϱâ" src="http://www.cadvance.org/doc/images/icon/exec_button.gif" border=0></A><BR><BR> <HR class=grayHr> <BR><B>¸î °¡Áö Method ¸¦ ÀÌ¿ëÇÑ °£´ÜÇÑ ³»±â</B> <P class=mtext>¾î¶² ¿¹Á¦¸¦ Çϸé ÁÁÀ»Áö »ý°¢ÇÏ´Ù°¡ random() À̶ó´Â ¾ÆÁÖ Àç¹ÌÀÖ´Â Method¸¦ ÀÌ¿ëÇÏ¿© °£´ÜÇÑ ³»±â °ÔÀÓÀ» Çϳª ¸¸µé¾ú½À´Ï´Ù. random À̶ó´Â ´Ü¾î´Â ¸ð¸£±ä ÇØµµ ¾Æ¸¶ ÀÌ »çÀÌÆ®ÀÇ È¸¿ø´ÔµéÀ̳ª ÀÌ »çÀÌÆ®¸¦ ã¾Æ ¿À½Å ºÐÀ̶ó¸é ¾Æ¸¶ ¹«Àð°Ô ±Í¿¡ ÀÍÀº ´Ü¾îÀ̸®¶ó »ý°¢ÇÕ´Ï´Ù. Te... , Pro... , Zer... ÀÌ·¸°Ô 3 ´Ü¾îÀÇ ÀϺθ¸ ºÁµµ ¾Æ! ±×°Å... ÇÏ°í ¾Æ½ÇÅ×ÁÒ... ¿¹ ¸Â½À´Ï´Ù. ¹Ù·Î StarCraft ÀÇ Random Player¶ó°í ÀØÁö ¾Ê½À´Ï±î... ¾î¶² Á¾Á·ÀÌ °É¸±Áö ¸ð¸£´Â, ¾Æ¹« Á¾Á·À̳ª ´Ù ÀßÇÏ´Â ±×·± Gamer¸¦ ¶æÇÏÁÒ. À¯¸íÇÑ ¼±¼ö·Î´Â ¿ì¸® ³ª¶óÀÇ ÃÖÀαÔ, ÃÖÁø¿ì µîÀÌ ÀÖ°í Ǫ¸¥ ´«ÀÇ ¸¶¹ý»ç¶ó°í ºÒ¸®´Â ±â¿è ÆäÀÌÆ®¸® °°Àº ¼±¼ö, ±×¸®°í... ¹Ù·Î ÀÌ »ç¶÷...¤¾¤¾ <BR><BR>¾Æ·¡ÀÇ ¿¹Á¦´Â 0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö¸¦ ¹ß»ý½ÃŰ´Â random Method¸¦ ÀÌ¿ëÇÏ¿© 2°³ÀÇ ÀÓÀÇÀÇ ¼ö¸¦ ¹ß»ý½Ã۰í 10À» °öÇÏ¿© round Method·Î 0 ~ 10 »çÀÌÀÌ Á¤¼ö·Î ¸¸µç ´ÙÀ½ °¢°¢ a¿Í bÀÇ º¯¼ö¿¡ ÀúÀåÇÏ°í µÎ ¼öÀÇ Å©±â¸¦ max Method·Î ºñ±³ÇÑ ´ÙÀ½ ´©°¡ À̰å´ÂÁö ÆÇÁ¤ÇØ ÁÖ´Â ¾Æ¹«·± Á¶ÀÛÀÌ ¾ø´Â ¾ÆÁÖ °øÆòÇÑ ³»±â¶ó°í ÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶Ç ±×³É ÆÇÁ¤¸¸ ÇÏ¸é °Å±â¿¡ ºÒº¹ÇÒ ¼öµµ Àֱ⠶§¹®¿¡ Input field¿¡ ±× °ªÀ» Ãâ·ÂÇÏ°Ô ÇÏ´Â °úÁ¤ÀÔ´Ï´Ù.</P><!-- ÀÔ·Â pre ½ÃÀÛ --><B class=pos>ÀÔ·Â</B> <PRE class=input id=gamble><html> <head> <title>Gambling</title> <script type="text/javascript"> <!-- function who_win(){ var a = Math.round(Math.random() *10) <FONT color=#444400>// 0 ~ 10 »çÀÌÀÇ Á¤¼ö¸¦ ¹ßÇà ½ÃÄÑ a ¿¡ ÀúÀå</FONT> var b = Math.round(Math.random() *10) <FONT color=#444400>// 0 ~ 10 »çÀÌÀÇ Á¤¼ö¸¦ ¹ßÇà ½ÃÄÑ b ¿¡ ÀúÀå</FONT> var who = Math.max(a, b) <FONT color=#444400>// a, b Áß Å« ÂÊÀ» who¿¡ ÀúÀå</FONT> document.gamble.forA.value = a <FONT color=#444400>// nameÀÌ forA ÀÎ input field¿¡ a°ª Ãâ·Â</FONT> document.gamble.forB.value = b <FONT color=#444400>// nameÀÌ forB ÀÎ input field¿¡ b°ª Ãâ·Â</FONT> if(a == b) <FONT color=#444400>// a, b °¡ °°Àº °ªÀ̸é</FONT> { window.alert("µÎ ¼±¼ö ºñ°å½À´Ï´Ù. ") <FONT color=#444400>// µÎ ¼±¼ö ºñ°å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â</FONT> } else if(who == a) <FONT color=#444400>// ±×·¸Áö ¾Ê°í Å« ÂÊÀÌ a ¶ó¸é</FONT> { window.alert("a ¼±¼ö°¡ À̰å½À´Ï´Ù. ") <FONT color=#444400>// a ¼±¼ö°¡ À̰å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â</FONT> } else <FONT color=#444400>// ±×·¸Áö ¾ÊÀ¸¸é, Áï b°¡ Å©¸é</FONT> { window.alert("b ¼±¼ö°¡ À̰å½À´Ï´Ù. ") <FONT color=#444400>// b ¼±¼ö°¡ À̰å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â</FONT> } } // --> </script> <style type="text/css"> <!-- input{border:1px solid royalblue; background-color:gold;} <FONT color=#444400>/*input field type selector */</FONT> --> </style> </head> <body> <br /><br /><br /> <form name="gamble"> <p align="center"> a ÀÇ °á°ú : <input type="text" readonly="readonly" name="forA" /> ¢Ñ ¢Ð <input type="text" readonly="readonly" name="forB" /> : b ÀÇ °á°ú<br /><br /> <button onclick="who_win()">µµ¹ÚÀ» À§ÇÏ¿© Áö³ªÄ£ Á¤½Å °Ç°À» »ï°¡ÇսôÙ.</button> </p> </form> </body> </html> </PRE><!-- ÀÔ·Â pre ³¡--><A href="javascript:copy2Clipboard(gamble);open_window('../../include/code_executor.asp');"><IMG alt="ÄÚµå ½ÇÇà Çϱâ" src="http://www.cadvance.org/doc/images/icon/exec_button.gif" border=0></A><BR><BR><BR> <HR class=blackHr>
<H2>Math Object</H2> <P class=mtext>Math object´Â Math¶ó´Â ±ÛÀÚ¸¸ ºÁµµ ¾Ë ¼ö ÀÖµíÀÌ ¼öÇÐ(Mathemetics)¿¡ »ç¿ëµÇ´Â Property¿Í Method µéÀ» ´Ù·ç´Â Object°¡ µÇ°Ú½À´Ï´Ù. »ç½Ç ÀúÀÇ °æ¿ì¿¡´Â ¾Æ·¡ Ç¥¿¡ ÀÖ´Â Propertyµé Áß¿¡ PI ¸¦ Á¦¿ÜÇÑ ³ª¸ÓÁö µéÀº ½ÇÇàÇØ º» ÀûÀº À־ »ç¿ëÇØ º»ÀûÀº ´Ü ÇÑ ¹øµµ ¾ø±¸¿ä. µÎ ¹øÂ° Ç¥ÀÇ Method Áß¿¡¼´Â round(), ceil(), floor(), random(), max(), min() ÀÌ·¸°Ô 6°³ À̿ܿ¡´Â ½ÇÁ¦·Î »ç¿ëÇØ º¸Áö ¾Ê¾Ò½À´Ï´Ù. ±×·¸Áö¸¸ ÀÌ·± Property³ª Method°¡ ÇÊ¿äÇÑ »ç¶÷¿¡°Ô´Â ²À ÀÖ¾î¾ß µÇ´Â °Í µéÀ̰ÚÁÒ. º°·Î »ç¿ëÇØ º¸Áö ¾ÊÀº °Í µéÀ̶ó ÀÌ·¸°Ô °Á·Π²Ù¹Ì·Á´Ù º¸´Ï NetScape, W3C, MSDN, ECMA µîÀ» µÚÁ®¼ Á¤È®¼ºÀ» ±âÇß½À´Ï´Ù. ±×·¯°í º¸´Ï ÀÌ ÆäÀÌÁö´Â °Á¶ó±â º¸´Ù Á¦ ½º½º·Î °øºÎ¸¦ ÇÑ ¼ÀÀ̷২ä...^^<BR><BR><B>*** JavaScript ´ë¼Ò¹®ÀÚ¸¦ Á¤È®È÷ ±¸ºÐÇÑ´Ù´Â »ç½ÇÀ» Ç×»ó ÀØÀ¸¸é ¾È µÇ°Ú½À´Ï´Ù...</B></P> <TABLE class=attributeTbl cellSpacing=2 cellPadding=0 border=0> <CAPTION class=general><B>NN</B> : <B>N</B>etscape <B>N</B>avigator, <B>IE</B> : <B>I</B>nternet <B>E</B>xplorer (Property¿Í Method¸¦ ó¸®ÇÏ´Â ÃÖ¼Ò ºê¶ó¿ìÀú ¹öÀü)</CAPTION> <TBODY> <TR> <TD class=titleCell colSpan=4>Math Object Properties</TD></TR> <COLGROUP> <COL class=syntaxLeftCell width="15%"> <COL class=syntaxRightCell> <COL class=syntaxRightCell style="TEXT-ALIGN: center" span=2> <TBODY> <TR class=syntaxLeftCell> <TD>Properties</TD> <TD align=middle>¼³ ¸í</TD> <TD width="4%">NN</TD> <TD width="4%">IE </TD></TR> <TR> <TD>E</TD> <TD>ÀÚ¿¬ LOGÀÇ ¹Ø(base) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LN2</TD> <TD>2ÀÇ ÀÚ¿¬ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LN10</TD> <TD>10ÀÇ ÀÚ¿¬ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LOG2E</TD> <TD>¹Ø(base)ÀÌ 2ÀÎ EÀÇ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>LOG10E</TD> <TD>¹Ø(base)ÀÌ 10ÀÎ EÀÇ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>PI</TD> <TD>PI(¿øÁÖÀ²) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>SQRT1_2</TD> <TD>1 / 2 Á¦°ö±Ù return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>SQRT2</TD> <TD>2 Á¦°ö±Ù return</TD> <TD>2.0</TD> <TD>3.0</TD></TR></TBODY></TABLE><BR><BR><!-- ÀÔ·Â pre ½ÃÀÛ --><B class=pos>Math Object Property ¿¹Á¦</B> <PRE class=input id=math_properties><html> <head> <title>Math °ü·Ã Properties</title> <script type="text/javascript"> <!-- document.write("Math.<b>E</b> = " + Math.E +"<br>") document.write("Math.<b>LN2</b> = " + Math.LN2 +"<br>") document.write("Math.<b>LN10</b> = " + Math.LN10 +"<br>") document.write("Math.<b>LOG2E</b> = " + Math.LOG2E +"<br>") document.write("Math.<b>LOG10E</b> = " + Math.LOG10E +"<br>") document.write("Math.<b>PI</b> = " + Math.PI +"<br>") document.write("Math.<b>SQRT2</b> = " + Math.SQRT2 +"<br>") document.write("Math.<b>SQRT1_2</b> = " + Math.SQRT1_2 ) // --> </script> </head> <body> </body> </html> </PRE><!-- ÀÔ·Â pre ³¡--><A href="javascript:copy2Clipboard(math_properties);open_window('../../include/code_executor.asp');"><IMG alt="ÄÚµå ½ÇÇà Çϱâ" src="http://www.cadvance.org/doc/images/icon/exec_button.gif" border=0></A><BR><BR> <HR class=grayHr> <BR><B>Math ObjectÀÇ Method</B> <P class=mtext>¾Æ·¡ÀÇ Method Áß¿¡ random(), round(), ceil(), floor(), max(), min() µîÀº ¾î´À ºÐ¾ß³ª ¾µ ¸ð°¡ ¸¹Àº MethodÀ̹ǷΠÀß ¾Ë¾Æ µÎ¸é À¯¿ëÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖÁ®...</P> <TABLE class=attributeTbl cellSpacing=2 cellPadding=0 border=0> <CAPTION class=general><B>NN</B> : <B>N</B>etscape <B>N</B>avigator, <B>IE</B> : <B>I</B>nternet <B>E</B>xplorer (Property¿Í Method¸¦ ó¸®ÇÏ´Â ÃÖ¼Ò ºê¶ó¿ìÀú ¹öÀü)</CAPTION> <TBODY> <TR> <TD class=titleCell colSpan=4>Math Object Methods</TD></TR> <COLGROUP> <COL class=syntaxLeftCell width="15%"> <COL class=syntaxRightCell> <COL class=syntaxRightCell style="TEXT-ALIGN: center" span=2> <TBODY> <TR class=syntaxLeftCell> <TD>Methods</TD> <TD align=middle>¼³ ¸í</TD> <TD width="4%">NN</TD> <TD width="4%">IE</TD></TR> <TR> <TD>abs(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ Àý´ë°ª(absolute Value) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>acos(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ arccosine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>asin(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ arcsine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>atan(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ arctangent °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>atan2(<I><FONT color=#941919>y,x</FONT></I>)</TD> <TD>X Ãà°ú ¾î¶² ÁÂÇ¥(x,y)°¡ ÀÌ·ç´Â °¢µµ(-pi ~ pi »çÀÌÀÇ radian °ª) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>ceil(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> °¡ ¼Ò¼öÀÏ °æ¿ì ¹«Á¶°Ç ¹Ý¿Ã¸² ¶Ç´Â Á¤¼öÀ̸é <I><FONT color=#941919>x</FONT></I> °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>cos(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ cosine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>exp(<I><FONT color=#941919>x</FONT></I>)</TD> <TD>ÀÚ¿¬ LOG EÀÇ Áö¼ö (ò¦â¦ : exponent) <I><FONT color=#941919>x</FONT></I> °ª (E<SUP>x</SUP> :E ÀÇ <I><FONT color=#941919>x</FONT></I> ã« ) return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>floor(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> °¡ ¼Ò¼öÀÏ °æ¿ì ¹«Á¶°Ç ¹Ý³»¸²(Àý»ç) ¶Ç´Â Á¤¼öÀ̸é x °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>log(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ ÀÚ¿¬ LOG °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>max(<I><FONT color=#941919>x,y</FONT></I>)</TD> <TD><I><FONT color=#941919>x, y</FONT></I> Áß¿¡¼ Å« °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>min(<I><FONT color=#941919>x,y</FONT></I>)</TD> <TD><I><FONT color=#941919>x, y</FONT></I> Áß¿¡¼ ÀÛÀº °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>pow(<I><FONT color=#941919>x,y</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ <I><FONT color=#941919>y</FONT></I> ½Â(ã«) °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>random()</TD> <TD>0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>round(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ ¹Ý¿Ã¸² °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>sin(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ sine °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>sqrt(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ Á¦°ö±Ù °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR> <TR> <TD>tan(<I><FONT color=#941919>x</FONT></I>)</TD> <TD><I><FONT color=#941919>x</FONT></I> ÀÇ tangent °ª return</TD> <TD>2.0</TD> <TD>3.0</TD></TR></TBODY></TABLE><BR><BR><!-- ÀÔ·Â pre ½ÃÀÛ --><B class=pos>Math Object Method ¿¹Á¦</B> <PRE class=input id=math_methods><html> <head> <title>Math °ü·Ã Methods</title> <script type="text/javascript"> <!-- document.write("-3.5ÀÇ Àý´ë°ªÀº : " + Math.<B>abs</B>(-3.5) + "<br />") document.write("PIÀÇ sine °ªÀº : " + Math.<B>sin</B>(Math.PI/2) + "<br />") document.write("PIÀÇ cosine °ªÀº : " + Math.<B>cos</B>(Math.PI/2) + "<br />") document.write("PIÀÇ tangent °ªÀº : " + Math.<B>tan</B>(Math.PI/2) + "<br />") document.write("0.5ÀÇ arcsine °ªÀº : " + Math.<B>asin</B>(0.5) + "<br />") document.write("0.5ÀÇ arccosine °ªÀº : " + Math.<B>acos</B>(0.5) + "<br />") document.write("0.5ÀÇ arctangent °ªÀº : " + Math.<B>atan</B>(0.5) + "<br />") document.write("ÁÂÇ¥ (3, 5)¿Í X ÃàÀÇ °¢µµ(radian)´Â : " + Math.<B>atan2</B>(3,5) + "<br />") document.write("ÀÚ¿¬ LOG EÀÇ 10½ÂÀº : " + Math.<B>exp</B>(10) + "<br />") document.write("4.9ÀÇ ¹«Á¶°Ç ¹Ý³»¸² °ªÀº : " + Math.<B>floor</B>(4.9) + "<br />") document.write("4.1ÀÇ ¹«Á¶°Ç ¹Ý¿Ã¸² °ªÀº : " + Math.<B>ceil</B>(4.1) + "<br />") document.write("10ÀÇ ÀÚ¿¬ LOG °ªÀº : " + Math.<B>log</B>(10) + "<br />") document.write("3°ú 5Áß¿¡ ´õ Å« ¼ö´Â : " + Math.<B>max</B>(3,5) + "<br />") document.write("3°ú 5Áß¿¡ ´õ ÀÛÀº ¼ö´Â : " + Math.<B>min</B>(3,5) + "<br />") document.write("2ÀÇ 3½Â(2<sup>3</sup>)Àº : " + Math.<B>pow</B>(2,3) + "<br />") document.write("0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö´Â ¸Ö±î? : " + Math.<B>random</B>() + "<br />") document.write("4.4999ÀÇ ¹Ý¿Ã¸² °ªÀº : " + Math.<B>round</B>(4.4999) + "<br />") document.write("2ÀÇ Á¦°ö±Ù °ªÀº : " + Math.<B>sqrt</B>(2) + "<br />") document.write("0 ~ 100 »çÀÌÀÇ ÀÓÀÇÀÇ Á¤¼ö´Â ¸Ö±î? : " + Math.<B>round</B>(Math.<B>random</B>() * 100)) <FONT color=#444400>// Math.random() ÀÇ °æ¿ì´Â '½ÇÇà °á°ú º¸±â' ´ÜÃ߸¦ ´©¸¦ ¶§ ¸¶´Ù ´Þ¶óÁý´Ï´Ù.</FONT> // --> </script> </head> <body> </body> </html> </PRE><!-- ÀÔ·Â pre ³¡--><A href="javascript:copy2Clipboard(math_methods);open_window('../../include/code_executor.asp');"><IMG alt="ÄÚµå ½ÇÇà Çϱâ" src="http://www.cadvance.org/doc/images/icon/exec_button.gif" border=0></A><BR><BR> <HR class=grayHr> <BR><B>¸î °¡Áö Method ¸¦ ÀÌ¿ëÇÑ °£´ÜÇÑ ³»±â</B> <P class=mtext>¾î¶² ¿¹Á¦¸¦ Çϸé ÁÁÀ»Áö »ý°¢ÇÏ´Ù°¡ random() À̶ó´Â ¾ÆÁÖ Àç¹ÌÀÖ´Â Method¸¦ ÀÌ¿ëÇÏ¿© °£´ÜÇÑ ³»±â °ÔÀÓÀ» Çϳª ¸¸µé¾ú½À´Ï´Ù. random À̶ó´Â ´Ü¾î´Â ¸ð¸£±ä ÇØµµ ¾Æ¸¶ ÀÌ »çÀÌÆ®ÀÇ È¸¿ø´ÔµéÀ̳ª ÀÌ »çÀÌÆ®¸¦ ã¾Æ ¿À½Å ºÐÀ̶ó¸é ¾Æ¸¶ ¹«Àð°Ô ±Í¿¡ ÀÍÀº ´Ü¾îÀ̸®¶ó »ý°¢ÇÕ´Ï´Ù. Te... , Pro... , Zer... ÀÌ·¸°Ô 3 ´Ü¾îÀÇ ÀϺθ¸ ºÁµµ ¾Æ! ±×°Å... ÇÏ°í ¾Æ½ÇÅ×ÁÒ... ¿¹ ¸Â½À´Ï´Ù. ¹Ù·Î StarCraft ÀÇ Random Player¶ó°í ÀØÁö ¾Ê½À´Ï±î... ¾î¶² Á¾Á·ÀÌ °É¸±Áö ¸ð¸£´Â, ¾Æ¹« Á¾Á·À̳ª ´Ù ÀßÇÏ´Â ±×·± Gamer¸¦ ¶æÇÏÁÒ. À¯¸íÇÑ ¼±¼ö·Î´Â ¿ì¸® ³ª¶óÀÇ ÃÖÀαÔ, ÃÖÁø¿ì µîÀÌ ÀÖ°í Ǫ¸¥ ´«ÀÇ ¸¶¹ý»ç¶ó°í ºÒ¸®´Â ±â¿è ÆäÀÌÆ®¸® °°Àº ¼±¼ö, ±×¸®°í... ¹Ù·Î ÀÌ »ç¶÷...¤¾¤¾ <BR><BR>¾Æ·¡ÀÇ ¿¹Á¦´Â 0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö¸¦ ¹ß»ý½ÃŰ´Â random Method¸¦ ÀÌ¿ëÇÏ¿© 2°³ÀÇ ÀÓÀÇÀÇ ¼ö¸¦ ¹ß»ý½Ã۰í 10À» °öÇÏ¿© round Method·Î 0 ~ 10 »çÀÌÀÌ Á¤¼ö·Î ¸¸µç ´ÙÀ½ °¢°¢ a¿Í bÀÇ º¯¼ö¿¡ ÀúÀåÇÏ°í µÎ ¼öÀÇ Å©±â¸¦ max Method·Î ºñ±³ÇÑ ´ÙÀ½ ´©°¡ À̰å´ÂÁö ÆÇÁ¤ÇØ ÁÖ´Â ¾Æ¹«·± Á¶ÀÛÀÌ ¾ø´Â ¾ÆÁÖ °øÆòÇÑ ³»±â¶ó°í ÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶Ç ±×³É ÆÇÁ¤¸¸ ÇÏ¸é °Å±â¿¡ ºÒº¹ÇÒ ¼öµµ Àֱ⠶§¹®¿¡ Input field¿¡ ±× °ªÀ» Ãâ·ÂÇÏ°Ô ÇÏ´Â °úÁ¤ÀÔ´Ï´Ù.</P><!-- ÀÔ·Â pre ½ÃÀÛ --><B class=pos>ÀÔ·Â</B> <PRE class=input id=gamble><html> <head> <title>Gambling</title> <script type="text/javascript"> <!-- function who_win(){ var a = Math.round(Math.random() *10) <FONT color=#444400>// 0 ~ 10 »çÀÌÀÇ Á¤¼ö¸¦ ¹ßÇà ½ÃÄÑ a ¿¡ ÀúÀå</FONT> var b = Math.round(Math.random() *10) <FONT color=#444400>// 0 ~ 10 »çÀÌÀÇ Á¤¼ö¸¦ ¹ßÇà ½ÃÄÑ b ¿¡ ÀúÀå</FONT> var who = Math.max(a, b) <FONT color=#444400>// a, b Áß Å« ÂÊÀ» who¿¡ ÀúÀå</FONT> document.gamble.forA.value = a <FONT color=#444400>// nameÀÌ forA ÀÎ input field¿¡ a°ª Ãâ·Â</FONT> document.gamble.forB.value = b <FONT color=#444400>// nameÀÌ forB ÀÎ input field¿¡ b°ª Ãâ·Â</FONT> if(a == b) <FONT color=#444400>// a, b °¡ °°Àº °ªÀ̸é</FONT> { window.alert("µÎ ¼±¼ö ºñ°å½À´Ï´Ù. ") <FONT color=#444400>// µÎ ¼±¼ö ºñ°å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â</FONT> } else if(who == a) <FONT color=#444400>// ±×·¸Áö ¾Ê°í Å« ÂÊÀÌ a ¶ó¸é</FONT> { window.alert("a ¼±¼ö°¡ À̰å½À´Ï´Ù. ") <FONT color=#444400>// a ¼±¼ö°¡ À̰å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â</FONT> } else <FONT color=#444400>// ±×·¸Áö ¾ÊÀ¸¸é, Áï b°¡ Å©¸é</FONT> { window.alert("b ¼±¼ö°¡ À̰å½À´Ï´Ù. ") <FONT color=#444400>// b ¼±¼ö°¡ À̰å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â</FONT> } } // --> </script> <style type="text/css"> <!-- input{border:1px solid royalblue; background-color:gold;} <FONT color=#444400>/*input field type selector */</FONT> --> </style> </head> <body> <br /><br /><br /> <form name="gamble"> <p align="center"> a ÀÇ °á°ú : <input type="text" readonly="readonly" name="forA" /> ¢Ñ ¢Ð <input type="text" readonly="readonly" name="forB" /> : b ÀÇ °á°ú<br /><br /> <button onclick="who_win()">µµ¹ÚÀ» À§ÇÏ¿© Áö³ªÄ£ Á¤½Å °Ç°À» »ï°¡ÇսôÙ.</button> </p> </form> </body> </html> </PRE><!-- ÀÔ·Â pre ³¡--><A href="javascript:copy2Clipboard(gamble);open_window('../../include/code_executor.asp');"><IMG alt="ÄÚµå ½ÇÇà Çϱâ" src="http://www.cadvance.org/doc/images/icon/exec_button.gif" border=0></A><BR><BR><BR> <HR class=blackHr>
÷ºÎÆÄÀÏ
°ßÀû°è»êÇϱâ
ÀÛ¾÷ÀÇ·Ú
°ßÀû¹®ÀÇ
°øÁö»çÇ×