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
Binary file added homework7hangman/asset/gallows0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework7hangman/asset/gallows1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework7hangman/asset/gallows2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework7hangman/asset/gallows3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework7hangman/asset/gallows4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework7hangman/asset/gallows5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework7hangman/asset/gallows6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions homework7hangman/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.checkbox {
/* background-color:a; */
/* width: 200px; */
/* margin: 3px; */



}
.box {
display: inline;

border-radius: 3px;
border-color: black;
color: orange;
margin: 3px;
color: black;
width: 100px;
background-color: beige;
}

57 changes: 57 additions & 0 deletions homework7hangman/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="index.css" type="text/css" media="screen" charset="utf-8">
</head>
<body>
<h1>The Hangman Game</h1>

<div>
<button class = "button A"><h1>A</h1></button>
<button class = "button B"><h1>B</h1></button>
<button class = "button C"><h1>C</h1></button>
<button class = "button D"><h1>D</h1></button>
<button class = "button E"><h1>E</h1></button>
<button class = "button F"><h1>F</h1></button>
<button class = "button G"><h1>G</h1></button>
<button class = "button H"><h1>H</h1></button>
<button class = "button I"><h1>I</h1></button>
<button class = "button J"><h1>J</h1></button>
<button class = "button K"><h1>K</h1></button>
<button class = "button L"><h1>L</h1></button>
<button class = "button M"><h1>M</h1></button>
<button class = "button M"><h1>N</h1></button>
<button class = "button O"><h1>O</h1></button>
<button class = "button P"><h1>P</h1></button>
<button class = "button Q"><h1>Q</h1></button>
<button class = "button R"><h1>R</h1></button>
<button class = "button S"><h1>S</h1></button>
<button class = "button T"><h1>T</h1></button>
<button class = "button U"><h1>U</h1></button>
<button class = "button V"><h1>V</h1></button>
<button class = "button W"><h1>W</h1></button>
<button class = "button X"><h1>X</h1></button>
<button class = "button Y"><h1>Y</h1></button>
<button class = "button Z"><h1>Z</h1></button>


</div>



<div>
<img class= "img" src="asset/gallows0.jpg" alt="" width="200">
</div>

<div class = "checkbox">
</div>



<script src="index.js"></script>
</body>
</html>
123 changes: 123 additions & 0 deletions homework7hangman/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// 1. generate word from array?




// let hangManImg = document.querySelector(".img")



let words = ["APPLE", "CAR", "COMPUTER", "CODECORE"];

let word = words[Math.floor(Math.random() * words.length)];
console.log(word)

// let word = "HELLOW"
// console.log(word)
// // -------------- entered word --------------
// document.createElement('h1')


// box = document.createElement('div')
// box.style.backgroundColor = 'orange'
// box.innerHTML = '<h1> H </h1>'
// let checkbox = document.querySelector('.checkbox')
// checkbox.appendChild(box)


for(let i = 0; i<word.length; i++){
let box = document.createElement('h1')
box.classList.add('box')
box.style.backgroundColor = 'orange'
box.innerText = "_"
let checkbox = document.querySelector('.checkbox')
checkbox.appendChild(box)
}




// // ---------------


let kmark = 0
let winmark = 0

const allLetterButton = document.querySelectorAll(".button")
allLetterButton.forEach(letterNode => {
letterNode.addEventListener("click", event =>{
letterNode.style.backgroundColor = 'red';
setTimeout(function(){
letterNode.style.backgroundColor = '';
}, 300)
let pressedLetter = letterNode.innerText


let mark = 0
let chance = 5 - kmark

for(let i = 0; i<word.length; i++) {
let checkbox = document.querySelector('.checkbox')
let box = checkbox.children[i]


if (pressedLetter == word[i]){

if(box.innerText==word[i]){

}else{

box.innerText = word[i]


mark ++
winmark ++
console.log("winmark")
console.log(winmark)
// alert("Right Guess");
if (winmark ===word.length){
let winSound = new Audio("sounds/win.mp3");
winSound.play();
alert("u win")
}
return(i)
}
}
}

let img = document.querySelector("img")

if (mark ===0){
kmark ++
console.log("kmark")
console.log(kmark)

alert("No Match " + chance + " chances left");


let noPhoto = "asset/gallows" + kmark + ".jpg"
img.setAttribute('src', noPhoto)

if (kmark === 6){
let loseSound = new Audio("sounds/lose.mp3");
loseSound.play();
alert("GameOver the right word is " + word);
// window.location.reload();
return
}
}



let check = 0
for (let i = 0; i<word.length; i++){
let box = checkbox.children[i]
if(box.innerText==word[i]){
check ++
}
}


})
})

Binary file added homework7hangman/sounds/lose.mp3
Binary file not shown.
Binary file added homework7hangman/sounds/win.mp3
Binary file not shown.
89 changes: 89 additions & 0 deletions todo_CLI/todo_cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const readline = require('readline')

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

let welcomeMenu =
"\n\n😄Welcome to Todo List Application😄\n" + "------------------------------------"

let functionMenu =
"\nPlease choose one of the following functions:\n\n" + "(v) View • ( n ) New • (cX) Complete • (dX) Delete • (q) Quit\n\n"

// arrar to record the todo list
let arrTodoList = []

//function to turn arrary into a list on screen
let todoListContentMenu = function(){
for (let i = 0; i < arrTodoList.length; i++){
console.log("\n" + i + arrTodoList[i]);
}
return
}

console.log (welcomeMenu)

function view() {
if(arrTodoList.length === 0){
console.log("List is empty...\n")
return main()
}else{
todoListContentMenu()

return main()
}
}

function newItem (){
rl.question("\nwhat?\n \n", (answer2) => {
arrTodoList.push(`[]${answer2}`)
return main()
})
}

let completeAnswer
function complete (){
console.log(`\nCompleted \"${arrTodoList[completeAnswer].substring(2)}\"`)
arrTodoList[completeAnswer] = arrTodoList[completeAnswer].replace("[]", "[✓]")
return main()
}

let deleteAnswer
function deleteItem (){
if(arrTodoList[deleteAnswer][1] === "]"){
console.log(`\nDeleted \"${arrTodoList[deleteAnswer].substring(2)}\"`)
}else{
console.log(`\nDeleted \"${arrTodoList[deleteAnswer].substring(3)}\"`)
}
arrTodoList.splice(deleteAnswer,1);
return main()
}

function quit (){
console.log ("\nSee you soon! 😄")
rl.close()
}


function main(){
rl.question(functionMenu, (answer) => {
if(answer==='v') {
view();
}else if(answer==='n'){
newItem();
}else if(answer[0]==='c'){
completeAnswer = answer[1]
complete ();
}else if(answer[0]==='d'){
deleteAnswer = answer[1]
deleteItem ();
}else if(answer==='q'){
quit ();
}
})
}

main()