Jump to content

alzami

Members
  • Posts

    95
  • Joined

  • Last visited

Posts posted by alzami

  1. in my previous post i posted a problem about my javascript calculator .in my calculator in made a log button which base is 10;it shows a perfect integer result.say it gives accurately 2 if i want to find the log of 100.but if i want log of 104 it doesn't work;how can i solve that

    function log10(el){	var m=document.getElementById(el);		for(;{         var d=Math.pow(10,i);				 if(d==m.value){			 m.value=i;			 i=0;			 break;		 }		  i++;	}}	
  2. thanks !and one simple thing to ask tan 90(degree)is undefined but my clac shows a number which is quite big.16331778728383844 .i coverted it to degree.but its not showing undefined

    function trig(el,oprtr){	var m=document.getElementById(el);	var p=(m.value)*( Math.PI/180);	var v=Math.ceil(oprtr(p));	m.value=v;}
  3. i have made a calculator.where i want to put sin, cos and tan button .and thats not the problem.i want a single function to emplement sin ,tan ,cos without creating three different function.

    whole code is here...

    <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>.its{	width:32%;	font-size:20px;	color:blue;	margin:0 auto;	}#gets{	width:289px;	height:50px;	font-size:20px;	color:red;}</style></head><body><form style="background-color:grey;display:inline-block;height:290px;width:300px;padding:10px;"><input type="text" id="gets" value="calculator(press CLR to begin)"></br><input type="button" value="0" onClick="calc(this.value);" class="its"><input type="button" value="1" onClick="calc(this.value);" class="its" ><input type="button" value="+" onClick="calc(this.value);" class="its"> <input type="button" value="2" onClick="calc(this.value);" class="its"><input type="button" value="3" onClick="calc(this.value);" class="its"><input type="button" value="-" onClick="calc(this.value);" class="its"><input type="button" value="4" onClick="calc(this.value);" class="its"><input type="button" value="5" onClick="calc(this.value);" class="its"><input type="button" value="/" onClick="calc(this.value);" class="its" ><input type="button" value="6" onClick="calc(this.value);" class="its"><input type="button" value="7" onClick="calc(this.value);" class="its"><input type="button" value="*" onClick="calc(this.value);" class="its"><input type="button" value="8" onClick="calc(this.value);" class="its"><input type="button" value="9" onClick="calc(this.value);" class="its" ><input type="button" value="=" onClick="ev('gets');" class="its"><input type="button" value="sqrt" onClick="sqr('gets');" class="its" ><input type="button" value="%" onClick="calc(this.value);" class="its"><input type="button" value="CLR" onClick="clr('gets');"class="its" ><input type="button" value="log" onClick="logit('gets');" class="its" ><input type="button" value="sin" onClick="trig('gets',sin);" class="its" ><input type="button" value="tan" onClick="trig('gets',tan);" class="its"><input type="button" value="cos" onClick="trig('gets',cos);"class="its" ></form><script>function calc(i){document.getElementById("gets").value +=i;				}function ev(el){var c=eval(document.getElementById("gets").value);	document.getElementById("gets").value=c;}function clr(el){	var m=document.getElementById(el);	m.value="";}function sqr(el){var c=document.getElementById(el);var v=Math.sqrt(c.value);c.value=v;}function logit(el){	var c=document.getElementById(el);	var v=Math.log(c.value);	c.value=v;}function trig(el,oprtr){	var m=document.getElementById(el);	var v=Math.oprtr(m.value);	m.value=v;}</script></body></html>

    for convenience i am giving the codes for sin cos and tan seperately ...

    <input type="button" value="sin" onClick="trig('gets',sin);" class="its" ><input type="button" value="tan" onClick="trig('gets',tan);" class="its"><input type="button" value="cos" onClick="trig('gets',cos);"class="its" >

    i want those three executed using only one function.anyone explain to me why this doesn't work?and the script is ...

    function trig(el,oprtr){	var m=document.getElementById(el);	var v=Math.oprtr(m.value);	m.value=v;}
  4. the "+" sign is not adding in the div with others.why this happens.other numbers works fine but symbols don't acting like them

    <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>#inpts{	width:50px;	height:50px;	border:1px solid black;	}</style></head><body><div id="inpts"></div><input type="button" value=" 1 "  onClick="gets('inpts',1);"><input type="button" value=" 2 " onClick="gets('inpts',2);"><input type="button" value=" + " onClick="gets('inpts',+);"><input type="button" value=" = " onClick="gets('inpts',=);"><script>function gets(el,n){var m=document.getElementById(el);m.innerHTML += n;		}</script></body></html>
  5. actually how i see the function is

    1)onCLick show will start

    2)s=its_prop() will be called;

    3)as i set setTimeout() in a way that it will re-execute its_prop() until 1==10 ;

    4)it will then return true after its_prop() executed 10 times.

     

    it should be like that,isn't it?still confused

  6. i want to show a div onClick over a button.and stay there a for a little moment then disappear again.codes seems fine but not working...

    <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>#it{	width:250px;	height:100px;	background-color:green;	border-radius:5px;    display:none;}</style></head><body><input type="button" value=" click to view " onClick="show('it');"><div id="it"></div><script>var i=0;function show(el){	var m=document.getElementById(el);	m.style.display="block";     var s=its_prop();		 	if(s){		m.style.display="none";}}function its_prop(){		var d=document.getElementById("it");		d.style.display="block";		i++;				if(i==10){			clearTimeout(p);			i=0;			return true;		}		else{			var p=setTimeout(its_prop,100);		}	}	</script></body></html>
  7. i have made two radio buttons.which will show a perticular text in box when clicked.problem is once it's been checked i want to uncheck it if clicked again and when clicked another radio button as well.how can i do that stuff

    <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>#forms{	width:30px;	height:20px;	border:1px solid black;}</style></head><body><div id="forms"></div><input type="radio" value="player1" onClick="show('forms',1);"><input type="radio" value="player2" onClick="show('forms',2);"><script>function show(el,n){	var m=document.getElementById(el);	m.innerHTML="player"+n;}</script></body></html>
  8. i think a function can contain another function which will be called during execution

    so, i think it's possible .or can't ? feeling confused

    function show(){[...]whatever();}

    i have not encountered this type of code yet

    onClick="show(); whatever();"

    it would be helpful if you describe the topics to make it clear to me

  9. title will be "check a fucntion executed or not!"

    say i have a html element...

    <a   onClick="show();" >some text</a>

    after i clecked on the link the function show( ) will be executed.

    function show(){---------------------------;_________________;}

    in my script tag i have a if condition which i want to execute depending on show() is executed or not.if show() is executed if statement will execute and if not if will not be executed.how can i test that

    is it correct???i think not!!!

    <script>if(show()){    ---------------------------;------------------------------;}
  10. thanks for all your kind help guys.

    i've not learned php yet.hope i will soon.

    i have a question .can i change the title of this post? i want if any new learner like me doing the same might get a lot of help as well as a lot to learn from this post if he/she searched google.so if title change is possible i would like to know the name of the game in english so that i can replace the title with this name

     

    and again thanks for all your kind support and help...

     

    i have tried my best to make it as dynamic ###### possible.here is my finished product....

    <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>*{	margin:0px;	padding:0px;}#shape{	border:1px solid black;	width:200px;	height:200px;	position:absolute;	left:5px;}td{	border:1px solid black;	background-color:orange;}#lol{	border:1px solid green;height:100px;width:300px;	background-color:background: #a9db80;background: -moz-linear-gradient(top, #a9db80 0%, #96c56f 100%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a9db80), color-stop(100%,#96c56f));background: -webkit-linear-gradient(top, #a9db80 0%,#96c56f 100%);background: -o-linear-gradient(top, #a9db80 0%,#96c56f 100%);background: -ms-linear-gradient(top, #a9db80 0%,#96c56f 100%);background: linear-gradient(to bottom, #a9db80 0%,#96c56f 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a9db80', endColorstr='#96c56f',GradientType=0 );border-radius:5px;display:none;position:absolute;top:200px;left:400px;z-index:5000;font-size:30px;color:green;	}#whole{	background-image:url('black.png');	opacity:.8;	z-index:1000;	height:800px;;	width:100%;	position:absolute;	top:0px;	display:none;		}#playButton{	position:absolute;	top:250px;	z-index:2400;	width:125px;	height:40px;	border-radius:6px;	background-color:background: #f85032;background: -moz-linear-gradient(top,  #f85032 0%, #f16f5c 50%, #f6290c 51%, #f02f17 71%, #e73827 100%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f85032), color-stop(50%,#f16f5c), color-stop(51%,#f6290c), color-stop(71%,#f02f17), color-stop(100%,#e73827));background: -webkit-linear-gradient(top,  #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%);background: -o-linear-gradient(top,  #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%);background: -ms-linear-gradient(top,  #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%);background: linear-gradient(to bottom,  #f85032 0%,#f16f5c 50%,#f6290c 51%,#f02f17 71%,#e73827 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f85032', endColorstr='#e73827',GradientType=0 );color:pink;font-size:20px;}.tableShape{	width:33%;	height:33%;	font-size:30px;	text-align:center;	color:red;}#playBtn{	position:absolute;	top:250px;	left:200px;	z-index:2400;	width:215px;	height:40px;	border-radius:6px;	background-color:background: #b8e1fc;background: -moz-linear-gradient(top,  #b8e1fc 0%, #a9d2f3 10%, #90bae4 25%, #90bcea 37%, #90bff0 50%, #6ba8e5 51%, #a2daf5 83%, #bdf3fd 100%);background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b8e1fc), color-stop(10%,#a9d2f3), color-stop(25%,#90bae4), color-stop(37%,#90bcea), color-stop(50%,#90bff0), color-stop(51%,#6ba8e5), color-stop(83%,#a2daf5), color-stop(100%,#bdf3fd));background: -webkit-linear-gradient(top,  #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%);background: -o-linear-gradient(top,  #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%);background: -ms-linear-gradient(top,  #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%);background: linear-gradient(to bottom,  #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%);filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b8e1fc', endColorstr='#bdf3fd',GradientType=0 );color:blue;font-size:20px;text-align:center;}</style></head><body style="position:relative;background-image:url('colorful.jpg');"><table id="shape"><tr ><td onClick="add(this.id,0,0);" id="td1" class="tableShape"></td><td onClick="add(this.id,0,1);" id="td2" class="tableShape"></td><td onClick="add(this.id,0,2);" id="td3" class="tableShape"></td></tr><tr ><td onClick="add(this.id,1,0);" id="td4" class="tableShape" ></td><td onClick="add(this.id,1,1);" id="td5" class="tableShape"></td><td onClick="add(this.id,1,2);" id="td6" class="tableShape"></td></tr><tr ><td onClick="add(this.id,2,0);" id="td7" class="tableShape"></td><td onClick="add(this.id,2,1);" id="td8" class="tableShape"></td><td onClick="add(this.id,2,2);" id="td9" class="tableShape"></td></tr></table><input type="button" value="  Reset  " onClick="reset();" id="playButton"><input type="button" value="  select players option" onClick="start();" id="playBtn"><div id="lol"></div><div id="whole"></div><script>var x;var y;var s;var t;var g;function start(){	 document.getElementById("playBtn").style.display="none";	 x=prompt("enter first player name","player1"); y=prompt("enter second player","player2"); s=prompt("choose p1 o/x"); t=prompt("choose p2 o/x"); start.lst=true;}</script><script>var d=1;var arr =new Array(3);for (i=0; i <3; i++){arr[i]=new Array(3);}var i=1;function add(el,r,c){	var m=document.getElementById(el);	if (i%2==1){				if(arr[r][c]){					    return false;		}		if(start.lst==true){			i++;		m.innerHTML=s;		arr[r][c]=m.innerHTML;		if((arr[0][0]==s && arr[0][1]==s && arr[0][2]==s) ||(arr[1][0]==s && arr[1][1]==s && arr[1][2]==s)||(arr[2][0]==s && arr[2][1]==s && arr[2][2]==s)||(arr[0][0]==s && arr[1][1]==s && arr[2][2]==s)||(arr[0][0]==s && arr[1][0]==s && arr[2][0]==s)|| (arr[0][1]==s && arr[1][1]==s && arr[2][1]==s)||(arr[0][2]==s && arr[1][2]==s && arr[2][2]==s)||(arr[0][2]==s && arr[1][1]==s && arr[2][0]==s)){							var k=document.getElementById("whole");	k.style.display="block";		var r=document.getElementById("lol");		r.style.display="block";		r.style.textAlign="center";		r.innerHTML="player "+x+ " wins";		}		}	}		else if(i%2==0){		if(arr[r][c]){						return false;		}if(start.lst==true){			i++;		m.innerHTML=t;		arr[r][c]=m.innerHTML;		 if((arr[0][0]==t && arr[0][1]==t && arr[0][2]==t) ||(arr[1][0]==t && arr[1][1]==t && arr[1][2]==t)||(arr[2][0]==t && arr[2][1]==t && arr[2][2]==t)||(arr[0][0]==t && arr[1][1]==t && arr[2][2]==t)||(arr[0][0]==t && arr[1][0]==t && arr[2][0]==t)|| (arr[0][1]==t && arr[1][1]==t && arr[2][1]==t)||(arr[0][2]==t && arr[1][2]==t && arr[2][2]==t)||(arr[0][2]==t && arr[1][1]==t && arr[2][0]==t)){				var k=document.getElementById("whole");	k.style.display="block";		var r=document.getElementById("lol");		r.style.display="block";		r.style.textAlign="center";		r.innerHTML="player "+y+ " wins"  ;		 }		}	}	}</script><script>function reset(){	var p=1;	for(m=0;m<3;m++){		for(n=0;n<3;n++){			arr[m][n]="";			document.getElementById("td"+p).innerHTML="";			p++;		}	}	i=1;	document.getElementById("playBtn").style.display="block";	var k=document.getElementById("whole");	k.style.display="none";	var r=document.getElementById("lol");		r.style.display="none";		r.innerHTML="";	start.lst=false;	s="";	t="";}	</script></body></html>
  11. created this and works finally.but its a mess.any other way to make it nice and simple

    <script>var arr =new Array(3)for (i=0; i <3; i++){arr[i]=new Array(3)}</script><script>var i=0;function add(el,r,c){	var m=document.getElementById(el);	i++;	if (i%2==1){		m.innerHTML="o";		arr[r][c]=m.innerHTML;		if((arr[0][0]=="o" && arr[0][1]=="o" && arr[0][2]=="o") ||(arr[1][0]=="o" && arr[1][1]=="o" && arr[1][2]=="o")||(arr[2][0]=="o" && arr[2][1]=="o" && arr[2][2]=="o")||(arr[0][0]=="o" && arr[1][1]=="o" && arr[2][2]=="o")||(arr[0][0]=="o" && arr[1][0]=="o" && arr[2][0]=="o")|| (arr[0][1]=="o" && arr[1][1]=="o" && arr[2][1]=="o")||(arr[0][2]=="o" && arr[1][2]=="o" && arr[2][2]=="o")||(arr[0][2]=="o" && arr[1][1]=="o" && arr[2][0]=="o")){		alert("congratulations!!!!player 1 wins");		}		}		else if(i%2==0){		m.innerHTML="x";		arr[r][c]=m.innerHTML;		 if((arr[0][0]=="x" && arr[0][1]=="x" && arr[0][2]=="x") ||(arr[1][0]=="x" && arr[1][1]=="x" && arr[1][2]=="x")||(arr[2][0]=="x" && arr[2][1]=="x" && arr[2][2]=="x")||(arr[0][0]=="x" && arr[1][1]=="x" && arr[2][2]=="x")||(arr[0][0]=="x" && arr[1][0]=="x" && arr[2][0]=="x")|| (arr[0][1]=="x" && arr[1][1]=="x" && arr[2][1]=="x")||(arr[0][2]=="x" && arr[1][2]=="x" && arr[2][2]=="x")||(arr[0][2]=="x" && arr[1][1]=="x" && arr[2][0]=="x")){		alert("congratulations!!!!player2 wins");		}	}	}</script>
×
×
  • Create New...