Answers for "javascript 1+1game"

0

javascript 1+1game

// This script file was written by Luis
console.log("Start...")
var score = 0
var Try = 0
var ABlvl = 0
var ABmoney = 1
var Moneyplus = 1
var ABprice = 5
var chance = 25
var CHlvl = 0
var CHprice = 100
function sleep(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}
function getmoney(){
	var x = Math.floor((Math.random() * chance) + 1);
	var y = 1+x
	var z = 1+1
	document.getElementById("text").innerHTML = "1+1="+y
	if (y == z){
		document.getElementById("text2").innerHTML = "This is correct!";
		score = score + Moneyplus
		document.getElementById("score").innerHTML = "Money: "+score+"$";
	}else{
		document.getElementById("text2").innerHTML = "This is not correct! Try again!";
	}
	Try = Try + 1
	document.getElementById("Try").innerHTML = "Try's: "+Try;
}
function UPAUupdate(){
	if (score == ABprice){
		score = score - ABprice
		document.getElementById("score").innerHTML = "Money: "+score+"$";
		AB = 1
		ABlvl = ABlvl + 1
		Moneyplus = Moneyplus *2
		ABprice = ABprice *3
		document.getElementById("Moneyper").innerHTML = "Money per 1+1=2: "+Moneyplus+"$";
		document.getElementById("Costs1").innerHTML = "Costs: "+ABprice+"$";
		document.getElementById("UPABlvl").innerHTML = "Level: "+ABlvl;
	}else{
		if (score > ABprice){
			score = score - ABprice
			document.getElementById("score").innerHTML = "Money: "+score+"$";
			AB = 1
			Moneyplus = Moneyplus *2
			ABlvl = ABlvl + 1
			ABprice = ABprice *3
			document.getElementById("Moneyper").innerHTML = "Money per 1+1=2: "+Moneyplus+"$";
		    document.getElementById("Costs1").innerHTML = "Costs: "+ABprice+"$";
			document.getElementById("UPABlvl").innerHTML = "Level: "+ABlvl;
		}else{
			var togo = ABprice
			togo = togo - score
			document.getElementById("Error").innerHTML = "You don't have enough Money (Need "+togo+"$ more)";
			document.getElementById("UPABlvl").innerHTML = "Level: "+ABlvl;
		}
	}
}
function UPCHlvlt(){
	if (ABlvl == 2){
		UPCH();


	}else{
		if (ABlvl > 2){
			UPCH();

		}else{
			var lvlstogo = 2
			var lvlstogo = lvlstogo - ABlvl
			document.getElementById("Error").innerHTML = "To do this Update you need to update (Money per 1+1=2 Update) to level 2 (You're at level "+ABlvl+", you need "+lvlstogo+" more update/s)";
		}
	}
}
function UPCH(){
	if (score == CHprice){
		score = score - CHprice
		document.getElementById("score").innerHTML = "Money: "+score+"$";
		CHlvl = CHlvl + 1
		chance = chance - 2
		CHprice = CHprice *2
		document.getElementById("chance").innerHTML = "Chance for 1+1=2: 1 in "+chance;
		document.getElementById("Costs2").innerHTML = "Costs: "+CHprice+"$";
		document.getElementById("UPClvl").innerHTML = "Level: "+CHlvl;
   }else{
	   if (score > CHprice){
		score = score - CHprice
		document.getElementById("score").innerHTML = "Money: "+score+"$";
		CHlvl = CHlvl + 1
		chance = chance - 2
		CHprice = CHprice *2
		document.getElementById("chance").innerHTML = "Chance for 1+1=2: 1 in "+chance;
		document.getElementById("Costs2").innerHTML = "Costs: "+CHprice+"$";
		document.getElementById("UPClvl").innerHTML = "Level: "+CHlvl;

	   }else{
		var togo = CHprice
		togo = togo - score
		document.getElementById("Error").innerHTML = "You don't have enough Money (Need "+togo+"$ more)";
	   }

   }

}
document.getElementById("Button").onclick = function(){
	getmoney();
}
 document.getElementById("UPAB").onclick = function(){
    UPAUupdate();
}
document.getElementById("UPC").onclick = function(){
	UPCHlvlt();
}
Posted by: Guest on October-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language