ggalan
02-12-2012, 01:45 AM
i have left/right buttons, the right button pushes elements into an array.
if the user pushes the left button then pushes the right button, i want to check the right number against the array.
heres my code so far, any help would be greatly appreciated
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<style type="text/css">
div{float:left; margin-right:50px;}
</style>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
var num = 0;
var arr = [];
$(function(){
$('#btn1').click(function() {
num--;
$('#rec').html(num);
return false;
});
$('#btn2').click(function() {
num++;
arr.push(num);
$('#rec').html(num);
if( jQuery.inArray(num, arr) ){// doesnt work
// do nothing
}else{
$('#arrayRec').html(arr.join(','));
}
return false;
});
});
</script>
</head>
<body>
<div id="btn1"><a href="">left</a></div>
<div id="btn2"><a href="">right</a></div>
<div id="rec">0</div>
<div id="arrayRec">null</div>
</body>
</html>
if the user pushes the left button then pushes the right button, i want to check the right number against the array.
heres my code so far, any help would be greatly appreciated
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<style type="text/css">
div{float:left; margin-right:50px;}
</style>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
var num = 0;
var arr = [];
$(function(){
$('#btn1').click(function() {
num--;
$('#rec').html(num);
return false;
});
$('#btn2').click(function() {
num++;
arr.push(num);
$('#rec').html(num);
if( jQuery.inArray(num, arr) ){// doesnt work
// do nothing
}else{
$('#arrayRec').html(arr.join(','));
}
return false;
});
});
</script>
</head>
<body>
<div id="btn1"><a href="">left</a></div>
<div id="btn2"><a href="">right</a></div>
<div id="rec">0</div>
<div id="arrayRec">null</div>
</body>
</html>