JSFiddle - React, Tailwind, and code Playground

by jonathanmh

JavaScript

var slaying = true;

function youHit(){
    return Math.floor(Math.random()* 2);
}
function damageThisRound(){
	return Math.floor(Math.random() * 5 + 1);
}
var dragonHealth = 10;
var totalDamage = 0;

while(slaying){
	if (youHit()){
        var damage = damageThisRound()
		console.log('You hit dat for ' + damage + ' damage.');
		totalDamage += damage;
		if (totalDamage >= dragonHealth){
            console.log('\n You slayed the Dragon!\n\n');
			slaying = false;
		}
        else {
            console.log('Dragon still at ' + (dragonHealth - totalDamage) + 'HP');
        }
	}
	else {
		console.log('You are a failure!');
        console.log('Dragon still at ' + (dragonHealth - totalDamage) + 'HP');
	}
	
}