$('document').ready(function (){
var randomnumber=Math.floor(Math.random()*13);
var randomnumber2=Math.floor(Math.random()*13);
var num = randomnumber;
var num2 = randomnumber2;
var stay = false;
var stay2 = true;
comply = true;
var comprandom = Math.floor(Math.random()*13);
var comprandom2 = Math.floor(Math.random()*13);
if(comprandom>10){
comprandom = 10;
}
if(comprandom===0){
comprandom = 1;
}
if(comprandom2>10){
comprandom2 = 10;
}
if(comprandom2===0){
comprandom2 = 1;
}
var total2 = comprandom+comprandom2;
do{
var comprandom4 = Math.floor(Math.random()*13);
if(comprandom4>10){
comprandom4 = 10;
}
if(total2<=15){
total2 = total2 + comprandom4;
}
else{
stay2 = false;
}
}while(stay2 == true)
if(num>10){
num = 10;
}
if(num2===0){
num2 = 1;
}
if(num===0){
num = 1;
}
if(num2>10){
num2 = 10;
}
var total = num + num2;
alert("You've got the number " + num + " and the number " + num2 + " for a total of " + total + ".");
do{
if(total>21){
alert("You busted.");
stay = true;
}
var randomnumber3=Math.floor(Math.random()*13);
var num3 = randomnumber3;
if(stay === false){
var input = prompt("Hit or Stay?");
}
if(input === "hit" && stay === false){if(num3>10){num3 = 10;}total = total + num3;alert("You got a " + num3 + " for a new total of " + total + ".");}if(input === "stay" && stay === false){alert("You stayed.");stay = true}}while(stay !== true)if(total2>21 && total> 21){alert("You and computer both busted!");}if(total2>21 && total<21){alert("You won because computer busted!");comply=false;}if(total>21 && total2<21){alert("Computer won because you busted!");comply=false;}if(total2>total && comply===true){alert("You had a " + total + " and Computer had a " + total2 + " so, Computer won!");}if(total>total2 && comply===true){alert("You had a " + total + " and Computer had a " + total2 + " so, you won!");}if(total === total2){alert("You had a " + total + " and Computer had a " + total2 + " so, you tied!");}});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.