Skip to content
Open
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
153 changes: 150 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,153 @@
console.log("hello script js");
////////////////////////////Part 1
// var secretWord = ['c', 'a', 't'];
// var corretLetters = []
// var flipTable = ['(', '╯', 'ರ', ' ~', ' ರ', ')', '╯', '︵', ' ┻', '━', '┻'];
// var currentTable = []
// var wrongGuesses = 0;

var inputHappened = function(currentInput){
console.log( currentInput );
return "WOW SOMETHING HAPPEND";
// var initialize = function(){
// document.getElementById('input').value = "";
// };


// var inputHappened = function(currentInput){
// console.log( currentInput );

// //Create a loop to loop secretWord with input
// for (var i=0; i<secretWord.length; i++){

// //if letter correct
// if(secretWord[i] === currentInput){

// //add letter to array and print array
// corretLetters.push(currentInput);

// //check if player won
// if (corretLetters.length === secretWord.length) {
// initialize();
// return `You WON!!! the word is CAT`
// }

// else{
// // print message
// initialize();
// return `you guessed right! your correct letters are ${corretLetters}`
// }

// }

// //if letter wrong
// else{

// // remove flipTable character and add to currentTable
// currentTable.push(flipTable.shift());

// //Keep track of number of wrong guesses
// wrongGuesses++;

// //if whole flip table, message game is over.
// if (flipTable.length === 0) {
// return `(╯ರ ~ ರ)╯︵ ┻━┻ YOU LOST!!!` ;
// }

// else {
// initialize();
// return `${currentTable}, you have made ${wrongGuesses} wrong guesses.`
// }
// }
// }
// };




////////////////////////////further 1
var secretWord = [
['c','a','t'],
['d','o','g','g','y'],
['a','l','p','h','a','b','e','t']
];

var totalLetters = 0;
for (var i=0; i<secretWord.length; i++){
for (var e=0; e<secretWord[i].length; e++){
totalLetters++;
}
}

var correctLetters = [[],[],[]];

var flipTable = ['(', '╯', 'ರ', ' ~', ' ರ', ')', '╯', '︵', ' ┻', '━', '┻'];
var currentTable = [];
var wrongGuesses = 0;

var initialize = function(){
document.getElementById('input').value = "";
};


var inputHappened = function(currentInput){
// console.log( currentInput );

//Create a loop in secretWord and loop again over the array to check for correct letter
for (var i=0; i<secretWord.length; i++){

for (var e=0; e<secretWord[i].length; e++){

//if letter correct but currentTable already has that letter
if (secretWord[i][e] === currentInput && secretWord[i][e] === correctLetters[i][e]) {
continue;
}


//if letter correct
else if(secretWord[i][e] === currentInput){

//remove letter from secretWord
// secretWord[i].splice(e, 1);
// console.log(secretWord);

//add letter to array in exact order and prin t array
console.log('i is: ' + i);
console.log('e is: ' + e);
correctLetters[i][e] = currentInput;
console.log(correctLetters);

//check if player won
if (correctLetters.length === totalLetters) {
initialize();
return `You WON!!! the word is CAT, DOGGY and ALPHABET`
}

else{
// print message
initialize();
console.log(correctLetters);
return `you guessed right! your correct letters are ${correctLetters.join()}`
}

}


}
}

//if no return executed, letter is wrong
// remove flipTable character and add to currentTable
currentTable.push(flipTable.shift());

//Keep track of number of wrong guesses
wrongGuesses++;

//if whole flip table, message game is over.
if (flipTable.length === 0) {
return `(╯ರ ~ ರ)╯︵ ┻━┻ YOU LOST!!!` ;
}

else {
initialize();
return `${currentTable.join("")}, you have made ${wrongGuesses} wrong guesses.`
}

};