View Single Post
Old 10-11-2012, 01:48 AM   PM User | #23
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I guess it could be something like this:
Code:
<body>
Input an action (eat, jump, walk followed by a space and your phrase, ie: Walk down the hill<br>
<input id="action" />
<input type="button" value="enter action" onclick="getWords()"/>
<script type="text/javascript">
function getWords(){
var val=document.getElementById("action").value
var act=val.substring(0,val.indexOf(" ")).toLowerCase();
var word=val.substring(val.indexOf(" "));
var acts={jump:function(){
			alert("you jump"+word)
			},
		eat:function(){
			alert("you eat"+word)
			},	
		walk:function(){
		alert("you walk"+word)
			}
	}
if (!acts[act]){alert("nothing happens")
return;
} else{
acts[act]()
	}
}

</script>
</body>
xelawho is offline   Reply With Quote