Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
</head>
<body>
<h3>DOM Manipulation Template</h3>
<input class="starter" id="input" placeholder="input"/>
<!-- restricted user to input only 1 char at a time -->
<input class="starter" id="input" placeholder="input" maxlength="1"/>
<h2>output:</h2>
<div class="starter" id="output"></div>
<script>
Expand All @@ -23,6 +24,7 @@ <h2>output:</h2>
var currentInput = event.target.value;
var result = inputHappened(currentInput)
display( result );
event.target.value = "";
});
</script>
<script src="script.js" charset="utf-8"></script>
Expand Down
70 changes: 69 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,74 @@
console.log("hello script js");

// containers
var foundArray = [];
var wrongArray = [];
var foundWord = "";

// wrong guesses
var flipTable = "(╯ರ ~ ರ)╯︵ ┻━┻";
var charFlipTable = flipTable.split("")
var newFlipTable = [];
var chance = charFlipTable.length;

// randomly select an animal in the array
var animals = ["cat", "lion", "horse", "turtle"]
var num = Math.floor(Math.random() * animals.length)
var original = animals[num];
var secretWord = original.split("");
var countingDown = secretWord.length;

// to hide the secret word with _
for (var i = 0; i < secretWord.length; i++) {
foundArray[i] = "_";
}

var inputHappened = function(currentInput){
console.log( currentInput );
return "WOW SOMETHING HAPPEND";
console.log(num)
var guessWord = currentInput.toLowerCase();

// isIncluded will return true if guessWord is found
var isIncluded = secretWord.includes(guessWord);

if (isIncluded === true) {
match(guessWord, secretWord);
console.log(secretWord)
foundArray[index] = foundWord;
countingDown--;
} else {
chance--
var flip = charFlipTable.shift();
newFlipTable.push(flip)
wrongArray.push(guessWord)
}

// display at different stages

var correct = foundArray.join(" ");
var success = foundArray.join("");
var flipflip = newFlipTable.join("")

if (original === success) {
return `Word found: ${original}!`
} else if (chance > 0) {
return `Found word: ${correct}
Remaining count: ${countingDown}
Chance left: ${chance}
${flipflip}`
} else {
return `You're dead ${flipflip}`
}
};

// function to match the guessWord to secretWord
// break is added to prevent overwriting the repeat string
var match = function(input, array) {
for (var i = 0; i < array.length; i++) {
if (input === array[i]) {
index = i
foundWord = array.splice(i, 1, "");
break;
}
}
}