Apologies if this sounds totally stupid but I'm a total dunce when it comes to coding! I'm trying to make a higher or lower guessing game using a deck of cards (i.e. The player guesses if the next card will be higher or lower than the one shown) but I don't really understand how to give each individual card a value.
For example I want to give the Ace card a value of "1" so then the person can guess if the next card will be higher or lower than 1.
I know arrays & classes are involved but I can't seem to find a tutorial that explains it in plain English. Here's my code so far (& yes I know it's dreadful!)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled</title>
<script language="javascript" type="text/javascript">
var ask=window.confirm("Do you understand the rules of Higher or Lower?")
if (ask)
window.alert("Lets go!")
else
window.alert("Guess if the next card shown will be higher or lower than the current card.")
function rollDice()
{
var diceArray = ["card0.jpg","card1.jpg","card2.jpg","card3.jpg","card4.jpg","card5.jpg"];
var pickCard = diceArray[Math.floor(Math.random() * diceArray.length)];
document.getElementById("cards").src = pickCard;
}
</script>
<link rel="stylesheet" target='_blank' href="teststyle.css" type="text/css">
</head>
<body style="text-align: center;">
<br>
<big style="font-weight: bold; font-family: Helvetica,Arial,sans-serif;"><big><big>HIGHER
OR LOWER?</big></big></big><br>
<h3>Use your knowledge of probability to guess if the next card will be
higher or lower!</h3>
<br>
<br>
<img src="card5.jpg" onload="pickCard()" id="cards"><br>
<br>
<span
style="font-weight: bold; font-family: Helvetica,Arial,sans-serif;">VALUES</span><span
style="font-family: Helvetica,Arial,sans-serif;">: ACE, TWO, THREE,
FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING</span><br>
<br>
<br>
</body>
</html>
really depends on your situation but there are a few ways you could do it. There isn't a "right" way I don't think.
You could use a switch
statement, but I think the more "javascript way" is you an object literal that maps your values like
var cardValues = {
"ace": 1,
"king": 13,
"queen": 12
}
//then you can get your card value from the 'name' very simply
var value = cardValues["ace"] // => 1
I want to attached function on click event on document. My function is attached it but it is calling it also. I don't understand why. Demo $(function () { $('a').click(function () { $(...
I want to attached function on click event on document. My function is attached it but it is calling it also. I don't understand why. Demo $(function () { $('a').click(function () { $(...
I am brand new to Angular, and have read through all the tutorials, but am at the steep point of the learning curve where I'm building a real application for the first time. I want to show a div ...
I am brand new to Angular, and have read through all the tutorials, but am at the steep point of the learning curve where I'm building a real application for the first time. I want to show a div ...
this is my html code <table id='code'> <tr> <td>data1</td> <td>data2</td> <td>data3</td> <td class='action'>...
this is my html code <table id='code'> <tr> <td>data1</td> <td>data2</td> <td>data3</td> <td class='action'>...
I just started using RequireJs. Only one problem. Can someone explain why the code inside the require block is not run on page refresh. It only runs when I clear the cache. example: require(['game','...
I just started using RequireJs. Only one problem. Can someone explain why the code inside the require block is not run on page refresh. It only runs when I clear the cache. example: require(['game','...