Math Object
Math object´Â Math¶ó´Â ±ÛÀÚ¸¸ ºÁµµ ¾Ë ¼ö ÀÖµíÀÌ ¼öÇÐ(Mathemetics)¿¡ »ç¿ëµÇ´Â Property¿Í Method µéÀ» ´Ù·ç´Â Object°¡ µÇ°Ú½À´Ï´Ù. »ç½Ç ÀúÀÇ °æ¿ì¿¡´Â ¾Æ·¡ Ç¥¿¡ ÀÖ´Â Propertyµé Áß¿¡ PI ¸¦ Á¦¿ÜÇÑ ³ª¸ÓÁö µéÀº ½ÇÇàÇØ º» ÀûÀº À־ »ç¿ëÇØ º»ÀûÀº ´Ü ÇÑ ¹øµµ ¾ø±¸¿ä. µÎ ¹øÂ° Ç¥ÀÇ Method Áß¿¡¼´Â round(), ceil(), floor(), random(), max(), min() ÀÌ·¸°Ô 6°³ À̿ܿ¡´Â ½ÇÁ¦·Î »ç¿ëÇØ º¸Áö ¾Ê¾Ò½À´Ï´Ù. ±×·¸Áö¸¸ ÀÌ·± Property³ª Method°¡ ÇÊ¿äÇÑ »ç¶÷¿¡°Ô´Â ²À ÀÖ¾î¾ß µÇ´Â °Í µéÀ̰ÚÁÒ. º°·Î »ç¿ëÇØ º¸Áö ¾ÊÀº °Í µéÀ̶ó ÀÌ·¸°Ô °Á·Π²Ù¹Ì·Á´Ù º¸´Ï NetScape, W3C, MSDN, ECMA µîÀ» µÚÁ®¼ Á¤È®¼ºÀ» ±âÇß½À´Ï´Ù. ±×·¯°í º¸´Ï ÀÌ ÆäÀÌÁö´Â °Á¶ó±â º¸´Ù Á¦ ½º½º·Î °øºÎ¸¦ ÇÑ ¼ÀÀ̷২ä...^^
*** JavaScript ´ë¼Ò¹®ÀÚ¸¦ Á¤È®È÷ ±¸ºÐÇÑ´Ù´Â »ç½ÇÀ» Ç×»ó ÀØÀ¸¸é ¾È µÇ°Ú½À´Ï´Ù...
NN : Netscape Navigator, IE : Internet Explorer (Property¿Í Method¸¦ ó¸®ÇÏ´Â ÃÖ¼Ò ºê¶ó¿ìÀú ¹öÀü)
| Math Object Properties |
| Properties |
¼³ ¸í |
NN |
IE |
| E |
ÀÚ¿¬ LOGÀÇ ¹Ø(base) return |
2.0 |
3.0 |
| LN2 |
2ÀÇ ÀÚ¿¬ LOG °ª return |
2.0 |
3.0 |
| LN10 |
10ÀÇ ÀÚ¿¬ LOG °ª return |
2.0 |
3.0 |
| LOG2E |
¹Ø(base)ÀÌ 2ÀÎ EÀÇ LOG °ª return |
2.0 |
3.0 |
| LOG10E |
¹Ø(base)ÀÌ 10ÀÎ EÀÇ LOG °ª return |
2.0 |
3.0 |
| PI |
PI(¿øÁÖÀ²) return |
2.0 |
3.0 |
| SQRT1_2 |
1 / 2 Á¦°ö±Ù return |
2.0 |
3.0 |
| SQRT2 |
2 Á¦°ö±Ù return |
2.0 |
3.0 |
Math Object Property ¿¹Á¦ <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>
Math ObjectÀÇ Method
¾Æ·¡ÀÇ Method Áß¿¡ random(), round(), ceil(), floor(), max(), min() µîÀº ¾î´À ºÐ¾ß³ª ¾µ ¸ð°¡ ¸¹Àº MethodÀ̹ǷΠÀß ¾Ë¾Æ µÎ¸é À¯¿ëÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖÁ®...
NN : Netscape Navigator, IE : Internet Explorer (Property¿Í Method¸¦ ó¸®ÇÏ´Â ÃÖ¼Ò ºê¶ó¿ìÀú ¹öÀü)
| Math Object Methods |
| Methods |
¼³ ¸í |
NN |
IE |
| abs(x) |
x ÀÇ Àý´ë°ª(absolute Value) return |
2.0 |
3.0 |
| acos(x) |
x ÀÇ arccosine °ª return |
2.0 |
3.0 |
| asin(x) |
x ÀÇ arcsine °ª return |
2.0 |
3.0 |
| atan(x) |
x ÀÇ arctangent °ª return |
2.0 |
3.0 |
| atan2(y,x) |
X Ãà°ú ¾î¶² ÁÂÇ¥(x,y)°¡ ÀÌ·ç´Â °¢µµ(-pi ~ pi »çÀÌÀÇ radian °ª) return |
2.0 |
3.0 |
| ceil(x) |
x °¡ ¼Ò¼öÀÏ °æ¿ì ¹«Á¶°Ç ¹Ý¿Ã¸² ¶Ç´Â Á¤¼öÀ̸é x °ª return |
2.0 |
3.0 |
| cos(x) |
x ÀÇ cosine °ª return |
2.0 |
3.0 |
| exp(x) |
ÀÚ¿¬ LOG EÀÇ Áö¼ö (ò¦â¦ : exponent) x °ª (Ex :E ÀÇ x ã« ) return |
2.0 |
3.0 |
| floor(x) |
x °¡ ¼Ò¼öÀÏ °æ¿ì ¹«Á¶°Ç ¹Ý³»¸²(Àý»ç) ¶Ç´Â Á¤¼öÀ̸é x °ª return |
2.0 |
3.0 |
| log(x) |
x ÀÇ ÀÚ¿¬ LOG °ª return |
2.0 |
3.0 |
| max(x,y) |
x, y Áß¿¡¼ Å« °ª return |
2.0 |
3.0 |
| min(x,y) |
x, y Áß¿¡¼ ÀÛÀº °ª return |
2.0 |
3.0 |
| pow(x,y) |
x ÀÇ y ½Â(ã«) °ª return |
2.0 |
3.0 |
| random() |
0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö return |
2.0 |
3.0 |
| round(x) |
x ÀÇ ¹Ý¿Ã¸² °ª return |
2.0 |
3.0 |
| sin(x) |
x ÀÇ sine °ª return |
2.0 |
3.0 |
| sqrt(x) |
x ÀÇ Á¦°ö±Ù °ª return |
2.0 |
3.0 |
| tan(x) |
x ÀÇ tangent °ª return |
2.0 |
3.0 |
Math Object Method ¿¹Á¦ <html>
<head>
<title>Math °ü·Ã Methods</title>
<script type="text/javascript">
<!--
document.write("-3.5ÀÇ Àý´ë°ªÀº : " + Math.abs(-3.5) + "<br />")
document.write("PIÀÇ sine °ªÀº : " + Math.sin(Math.PI/2) + "<br />")
document.write("PIÀÇ cosine °ªÀº : " + Math.cos(Math.PI/2) + "<br />")
document.write("PIÀÇ tangent °ªÀº : " + Math.tan(Math.PI/2) + "<br />")
document.write("0.5ÀÇ arcsine °ªÀº : " + Math.asin(0.5) + "<br />")
document.write("0.5ÀÇ arccosine °ªÀº : " + Math.acos(0.5) + "<br />")
document.write("0.5ÀÇ arctangent °ªÀº : " + Math.atan(0.5) + "<br />")
document.write("ÁÂÇ¥ (3, 5)¿Í X ÃàÀÇ °¢µµ(radian)´Â : " + Math.atan2(3,5) + "<br />")
document.write("ÀÚ¿¬ LOG EÀÇ 10½ÂÀº : " + Math.exp(10) + "<br />")
document.write("4.9ÀÇ ¹«Á¶°Ç ¹Ý³»¸² °ªÀº : " + Math.floor(4.9) + "<br />")
document.write("4.1ÀÇ ¹«Á¶°Ç ¹Ý¿Ã¸² °ªÀº : " + Math.ceil(4.1) + "<br />")
document.write("10ÀÇ ÀÚ¿¬ LOG °ªÀº : " + Math.log(10) + "<br />")
document.write("3°ú 5Áß¿¡ ´õ Å« ¼ö´Â : " + Math.max(3,5) + "<br />")
document.write("3°ú 5Áß¿¡ ´õ ÀÛÀº ¼ö´Â : " + Math.min(3,5) + "<br />")
document.write("2ÀÇ 3½Â(2<sup>3</sup>)Àº : " + Math.pow(2,3) + "<br />")
document.write("0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö´Â ¸Ö±î? : " + Math.random() + "<br />")
document.write("4.4999ÀÇ ¹Ý¿Ã¸² °ªÀº : " + Math.round(4.4999) + "<br />")
document.write("2ÀÇ Á¦°ö±Ù °ªÀº : " + Math.sqrt(2) + "<br />")
document.write("0 ~ 100 »çÀÌÀÇ ÀÓÀÇÀÇ Á¤¼ö´Â ¸Ö±î? : " + Math.round(Math.random() * 100))
// Math.random() ÀÇ °æ¿ì´Â '½ÇÇà °á°ú º¸±â' ´ÜÃ߸¦ ´©¸¦ ¶§ ¸¶´Ù ´Þ¶óÁý´Ï´Ù.
// -->
</script>
</head>
<body>
</body>
</html>
¸î °¡Áö Method ¸¦ ÀÌ¿ëÇÑ °£´ÜÇÑ ³»±â
¾î¶² ¿¹Á¦¸¦ Çϸé ÁÁÀ»Áö »ý°¢ÇÏ´Ù°¡ random() À̶ó´Â ¾ÆÁÖ Àç¹ÌÀÖ´Â Method¸¦ ÀÌ¿ëÇÏ¿© °£´ÜÇÑ ³»±â °ÔÀÓÀ» Çϳª ¸¸µé¾ú½À´Ï´Ù. random À̶ó´Â ´Ü¾î´Â ¸ð¸£±ä ÇØµµ ¾Æ¸¶ ÀÌ »çÀÌÆ®ÀÇ È¸¿ø´ÔµéÀ̳ª ÀÌ »çÀÌÆ®¸¦ ã¾Æ ¿À½Å ºÐÀ̶ó¸é ¾Æ¸¶ ¹«Àð°Ô ±Í¿¡ ÀÍÀº ´Ü¾îÀ̸®¶ó »ý°¢ÇÕ´Ï´Ù. Te... , Pro... , Zer... ÀÌ·¸°Ô 3 ´Ü¾îÀÇ ÀϺθ¸ ºÁµµ ¾Æ! ±×°Å... ÇÏ°í ¾Æ½ÇÅ×ÁÒ... ¿¹ ¸Â½À´Ï´Ù. ¹Ù·Î StarCraft ÀÇ Random Player¶ó°í ÀØÁö ¾Ê½À´Ï±î... ¾î¶² Á¾Á·ÀÌ °É¸±Áö ¸ð¸£´Â, ¾Æ¹« Á¾Á·À̳ª ´Ù ÀßÇÏ´Â ±×·± Gamer¸¦ ¶æÇÏÁÒ. À¯¸íÇÑ ¼±¼ö·Î´Â ¿ì¸® ³ª¶óÀÇ ÃÖÀαÔ, ÃÖÁø¿ì µîÀÌ ÀÖ°í Ǫ¸¥ ´«ÀÇ ¸¶¹ý»ç¶ó°í ºÒ¸®´Â ±â¿è ÆäÀÌÆ®¸® °°Àº ¼±¼ö, ±×¸®°í... ¹Ù·Î ÀÌ »ç¶÷...¤¾¤¾
¾Æ·¡ÀÇ ¿¹Á¦´Â 0 ~ 1 »çÀÌÀÇ ÀÓÀÇÀÇ ¼ö¸¦ ¹ß»ý½ÃŰ´Â random Method¸¦ ÀÌ¿ëÇÏ¿© 2°³ÀÇ ÀÓÀÇÀÇ ¼ö¸¦ ¹ß»ý½Ã۰í 10À» °öÇÏ¿© round Method·Î 0 ~ 10 »çÀÌÀÌ Á¤¼ö·Î ¸¸µç ´ÙÀ½ °¢°¢ a¿Í bÀÇ º¯¼ö¿¡ ÀúÀåÇÏ°í µÎ ¼öÀÇ Å©±â¸¦ max Method·Î ºñ±³ÇÑ ´ÙÀ½ ´©°¡ À̰å´ÂÁö ÆÇÁ¤ÇØ ÁÖ´Â ¾Æ¹«·± Á¶ÀÛÀÌ ¾ø´Â ¾ÆÁÖ °øÆòÇÑ ³»±â¶ó°í ÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶Ç ±×³É ÆÇÁ¤¸¸ ÇÏ¸é °Å±â¿¡ ºÒº¹ÇÒ ¼öµµ Àֱ⠶§¹®¿¡ Input field¿¡ ±× °ªÀ» Ãâ·ÂÇÏ°Ô ÇÏ´Â °úÁ¤ÀÔ´Ï´Ù.
ÀÔ·Â
<html>
<head>
<title>Gambling</title>
<script type="text/javascript">
<!--
function who_win(){
var a = Math.round(Math.random() *10) // 0 ~ 10 »çÀÌÀÇ Á¤¼ö¸¦ ¹ßÇà ½ÃÄÑ a ¿¡ ÀúÀå
var b = Math.round(Math.random() *10) // 0 ~ 10 »çÀÌÀÇ Á¤¼ö¸¦ ¹ßÇà ½ÃÄÑ b ¿¡ ÀúÀå
var who = Math.max(a, b) // a, b Áß Å« ÂÊÀ» who¿¡ ÀúÀå
document.gamble.forA.value = a // nameÀÌ forA ÀÎ input field¿¡ a°ª Ãâ·Â
document.gamble.forB.value = b // nameÀÌ forB ÀÎ input field¿¡ b°ª Ãâ·Â
if(a == b) // a, b °¡ °°Àº °ªÀ̸é
{
window.alert("µÎ ¼±¼ö ºñ°å½À´Ï´Ù. ") // µÎ ¼±¼ö ºñ°å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â
}
else if(who == a) // ±×·¸Áö ¾Ê°í Å« ÂÊÀÌ a ¶ó¸é
{
window.alert("a ¼±¼ö°¡ À̰å½À´Ï´Ù. ") // a ¼±¼ö°¡ À̰å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â
}
else // ±×·¸Áö ¾ÊÀ¸¸é, Áï b°¡ Å©¸é
{
window.alert("b ¼±¼ö°¡ À̰å½À´Ï´Ù. ") // b ¼±¼ö°¡ À̰å½À´Ï´Ù. ¸¦ °æ°íâ¿¡ Ãâ·Â
}
}
// -->
</script>
<style type="text/css">
<!--
input{border:1px solid royalblue; background-color:gold;} /*input field type selector */
-->
</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>