OK so i took a sample from a place where i was learning and expanded upon it, it isnt near to perfect, and doesnt do all i want it to, but heres were i am on it.
The following content has been hidden - Reason : long
var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var dragonHit = Math.floor(Math.random () *2);
var playerDamage = Math.floor(Math.random() * 80 + 1);
var dragonDamage = Math.floor(Math.random() * 20 + 1);
var totalDamage = 0;
var playerHealth = 100;
var dragonHealth = 200;
var totalDragonDamage = 0;
if(playerHealth > 0 || dragonHealth >0){
slaying = true;
}
while(slaying) {
if((playerHealth && dragonHealth > 1) && (youHit) && (dragonHit)) {
console.log("you hit the dragon!");
console.log("the dragon hits you!")
if(totalDamage>=dragonHealth) {
console.log("Gratz you killed the dragon");
slaying = false;
}else if(totalDragonDamage > playerHealth) {
console.log("the dragon hath slain thee")
}else{
console.log("you only hit for" + playerDamage +"the dragon still has " + dragonHealth + " health the dragon hits you for " + dragonDamage + "you still have " + playerHealth + "health");
}
} else if((playerHealth && dragonHealth >1)&& (youHit) && (dragonHit= false)){
console.log("you hit the dragon and the dragon missed")
totalDamage += playerDamage;
dragonHealth -= playerDamage
if(totalDamage > dragonHealth) {
console.log("Gratz you killed the dragon");
slaying = false
}else if(totalDragonDamage > playerHealth) {
console.log("the dragon hath slain thee")
}else {
console.log("you only hit the dragon for" + playerDamage + " the dragon still has "+ dragonHealth + " health. you still have " + playerHealth + "health.")
}
}else if (playerHealth&&dragonHealth>1 && (youHit = false) && (dragonHit)) {
console.log("you have missed, but the dragon hit you")
totalDragonDamage += dragonDamage;
playerHealth -= dragonDamage;
if(totalDragonDamage > playerHealth) {
console.log("the dragon hath slain thee");
slaying = false
}else {
console.log("the dragon only hit you for" + dragonDamage+ "damage, you still have "+ playerHealth +" Health left.")
}
} if ( (playerHealth && dragonHealth>1) && ((youHit = false) && (dragonHit = false)) ){
console.log("you have both missed");
slaying = false
The following content has been hidden - Reason : long
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}
function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
}
/*Create a search function
then call it passing "Jones"*/
function search(lastName){
var contactsLength = contacts.length;
for(var i = 0; i<contactsLength; i++) {
if(contacts[i].lastName === lastName ){
printPerson(contacts[i]);
}
}
}