javascript add image to varible
Posted: 02 Jul 2020, 16:44
Hello Coursesweb I do not known mutch about javascipts
& for view hours I gambling to try to get images in this javascript
I try with (example)
to add it in
Hope you van help me out ????
& for view hours I gambling to try to get images in this javascript
I try with (example)
Code: Select all
case 1 : return "Spades.png";
Code: Select all
<TD align=middle>Card(s):<INPUT type="text1" onfocus=guest.blur(); this.src=getImagePath(); size=4
value="Push DEAL to start" name=guest>
Hope you van help me out ????
Code: Select all
<SCRIPT language=JavaScript>
<!-- BEGIN --
var GameOver = 0;
var CardCount = 0;
var Advising = 0;
var HouseTxt, GuestTxt;
function Shuffle(max)
{
num=Math.random()*max;
return Math.round(num)+1;
}
function myFunction() {
var x = document.getElementById("suit").src;
document.getElementById("demo").innerHTML = x;
}
function GetSuit() {
suit = Shuffle(4);
switch(suit)
{
case 1 : return "Spades.png";
case 2 : return "Clubs.png";
case 3 : return "<img src='Diamonds.png' />";
default: return "Hearts.png";
}
}
function CardName(card)
{
switch(card)
{
case 1 : return "Ace";
case 11 : return "Jack";
case 12 : return "Queen";
case 13 : return "King";
case 2 : return "Molendijk";
default : return card;
}
}
function CardValue(f,card,who)
{
if(card == 1)
{
if(who == "You" && f.you.value >10)
{
f.guest.value = f.guest.value + " Low";
return 1;
}
else return 11;
}
if(card > 10) return 10;
return card;
}
function DrawCard(f,who)
{
card = Shuffle(12);
suit = GetSuit();
if(who == "You")
{
f.guest.value=(CardName(card) + " " + suit);
}
else
{
f.house.value=(CardName(card) + " " + suit);
}
return CardValue(f,card,who);
}
function NewHand(f)
{
if(GameOver !=0)
{
Advise(f,"A Hand is","Already in Play");
return;
}
else
{
f.dealer.value = 0;
f.you.value = 0;
CardCount=0;
f.dealer.value = eval(f.dealer.value) + DrawCard(f, "Dealer");
f.you.value = eval(f.you.value) + DrawCard(f, "You");
GameOver= -1;
CardCount+=1;
}
}
function Advise(f,top,btm)
{
if (!Advising)
{
Advising=-1;
HouseTxt=f.house.value;
GuestTxt=f.guest.value;
f.house.value=top;
f.guest.value=btm;
window.setTimeout("document.display.house.value=HouseTxt;"+
"document.display.guest.value=GuestTxt;"+
"Advising=0;", 600);
}
}
function Dealer(f)
{
if (!GameOver)
{
Advise(f,"Deal the Cards!","");
return;
}
else if(f.you.value<10)
{
Advise(f,"Not Below Ten!","Take a Hit!");
return;
}
else if (CardCount <2)
{
Advise(f,"Minimum 2 Cards!","Hit Again!");
return;
}
else while(f.dealer.value < 17)
{
f.dealer.value = eval(f.dealer.value) + DrawCard(f, "Dealer");
}
}
function Player(f)
{
if (!GameOver)
{
Advise(f,"Deal the Cards!","");
return;
}
else
{
CardCount +=1;
f.house.value="You Get...";
f.you.value = eval(f.you.value) + DrawCard(f, "You");
}
if(f.you.value > 21)
{
f.house.value="You Busted!";
GameOver=0;
f.score.value=eval(f.score.value)-1;
}
}
function Declare(f)
{
if (!GameOver || f.you.value<10 || CardCount <2)
{
return;
}
else if(f.dealer.value > 21)
{
f.house.value="House Busts!";
f.guest.value="You Win! $$$$$$";
GameOver=0;
f.score.value=eval(f.score.value)+1;
}
else if(f.you.value > f.dealer.value)
{
f.house.value="You Win!";
f.guest.value="$$$$$$$$$$$$$$$";
GameOver=0;
f.score.value=eval(f.score.value)+1;
}
else if(f.dealer.value == f.you.value)
{
f.house.value="Game Tied!";
f.guest.value="Try Again!";
GameOver=0;
f.score.value=eval(f.score.value)-1;
}
else
{
f.house.value="House Wins!";
f.guest.value="Tough Luck!";
GameOver=0;
f.score.value=eval(f.score.value)-1;
}
}
// -- END -->
</SCRIPT>
Code: Select all
<CENTER>
<FORM name=display>
<TABLE cellSpacing=0 cellPadding=5 border=0 bgcolor="#D8D8D8">
<TBODY>
<TR>
<TD align=middle>Score :</TD>
<TD align=middle>Dealer </TD>
<TD align=middle><INPUT type="textgamers" onfocus=dealer.blur(); size=4 name=dealer></TD>
<TD align=middle>Card(s):<INPUT type="text1" onfocus=house.blur(); size=18 id=searchbar
value=" ---Blackjack---" name=house></TD>
</TR>
<TR>
<TD align=middle><INPUT type="textgamers" onfocus=score.blur(); size=4 value=0 name=score></TD>
<TD align=middle>Player</TD>
<TD align=middle>
<INPUT type="textgamers" size=18 onfocus=you.blur(); size=4 name=you></TD>
<TD align=middle>Card(s):<INPUT type="text1" onfocus=guest.blur(); this.src=getImagePath(); size=4
value="Push DEAL to start" name=guest>
</TD></TR>
<TR>
<TD align=middle>
</TD>
<TD align=middle colSpan=3> <INPUT onclick=NewHand(this.form) size=18 type=button value=Deal name=deal>
<INPUT onclick=Dealer(this.form);Declare(this.form) type=button value=Stand>
<INPUT onclick=Player(this.form) type=button value=" Hit ">
</TD></TR></TBODY></TABLE></FORM></CENTER>