0
مشکل در جاوا اسکریپت
سلام دوستان
میخواستم یک تاس آنلاین با جاوا اسکریپت بنویسم ولی هر کاری کردم اجرا نشد میشه بگید مشکل دقیقا کجاست ؟
<html> <head> <meta charset="utf-8" /> <script> documnet.getElementById("click").onclick = tas ; function tas() { for (var i=0; i<3; i++) { var newNum = math.floor(math.random() * 6) ; documnet.getElementById("tas" + i).innerHTML = newNum ; } } </script> <style> #click { background-color : red ; color : white ; width : 440px ; height : 100px; font-size : 24px; font-family : B Koodak ; } #tas { width : 400px ; height : 200px; background : brown ; padding : 20px; } #tas1 { background : white ; width : 100px ; height : 100px ; float : right ; margin : 40px; font-size : 68px; } #tas2 { background : white ; width : 100px ; height : 100px ; float : left ; margin : 40px; font-size : 68px; } </style> </head> <body> <button id="click"> انداختن تاس </button> <div id="tas"> <div id="tas1"><center></center></div> <div id="tas2"></div> </div> </body> </html>
1 پاسخ
2
سلام به شما دوست عزیز.
شما هم غلط املایی در کدتون دارید مثل نوشتن document و math با m کوچیک و هم اشتباه منطقی و برنامه نویسی من کد شما رو به شکل زیر تغییر دادم والان درست است
<html> <head> <meta charset="utf-8" /> <style> #click { background-color : red ; color : white ; width : 440px ; height : 100px; font-size : 24px; font-family : B Koodak ; } #tas { width : 400px ; height : 200px; background : brown ; padding : 20px; } #tas1 { background : white ; width : 100px ; height : 100px ; float : right ; margin : 40px; font-size : 68px; } #tas2 { background : white ; width : 100px ; height : 100px ; float : left ; margin : 40px; font-size : 68px; } </style> </head> <body> <button id="click"> انداختن تاس </button> <div id="tas"> <div id="tas1"><center></center></div> <div id="tas2"></div> </div> <script> document.getElementById('click').onclick = tas ; function tas() { for (var i=0; i<3; i++) { var newNum = Math.floor(Math.random() * 6) ; if(i>0){ document.getElementById("tas" + i).innerHTML = newNum ; } } } </script> </body> </html>