Skip to content

Commit

Permalink
Feat: Add easterEgg fxn for pick rand num
Browse files Browse the repository at this point in the history
  • Loading branch information
JCBeldo committed Dec 26, 2023
1 parent 7855612 commit 9d96ace
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const locations = [
{
name: "kill monster",
"button text": ["Go to town square", "Go to town square", "Go to town square"],
"button functions": [goTown, goTown, goTown],
"button functions": [goTown, goTown, easterEgg],
text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.'
},
{
Expand Down Expand Up @@ -201,6 +201,7 @@ function attack() {
if (Math.random() > .1 && inventory.length !== 1) {
text.innerText += " Your " + inventory.pop() + " breaks.";
currentWeapon--;
}
}

function dodge() {
Expand All @@ -212,7 +213,7 @@ function isMonsterHit() {
}

function getMonsterAttackValue(level) {
const hit = (level * 5) -(Math.floor(Math.random() * xp));
const hit = (level * 5) - (Math.floor(Math.random() * xp));
console.log(hit);
return hit > 0 ? hit : 0;
}
Expand Down Expand Up @@ -243,4 +244,42 @@ function restart() {
healthText.innerText = health;
xpText.innerText = xp;
goTown();
}
}

function easterEgg() {
update(locations[7]);
}

function pickTwo() {
pick(2);
}

function pickEight() {
pick(8);
}

function pick(guess) {
let numbers = [];
while (numbers.length < 10) {
numbers.push(Math.floor(Math.random() * 11));
}
text.innerText = "You picked " + guess + ". Here are the random numbers:\n";
for (let i = 0; i < 10; i++) {
text.innerText += numbers[i] + "\n";
}
if (numbers.indexOf(guess) !== -1) {
text.innerText += "Right! You win 20 gold!";
gold += 20;
goldText.innerText = gold;
}
else {
text.innerText += "Wrong! You lose 10 health!";
health -= 10;
healthText.innerText = health;
if (health <= 0) {
lose();
}
}
}
// The indexOf() array method returns the first index at which a given
// element can be found in the array, or -1 if the element is not present.

0 comments on commit 9d96ace

Please sign in to comment.