Skip to content
Closed

Main2 #698

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
98 changes: 98 additions & 0 deletions Rock paper scisor/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Black+Ops+One&family=Silkscreen:wght@700&display=swap" rel="stylesheet">

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rock Paper Scisor</title>
<style>
* {
margin: 0;
padding: 0;
}

body {
align-items: center;
justify-content: center;
display: flex;
flex-direction: column;
height: 100vh;
padding: 14px;
}

.btn-container {
display: grid;
grid-template-columns: 1fr;
gap: 30px;
}

.btn {
padding: 20px 80px;
border-radius: 14px;
border: 1px solid black;
font-size: 1.5rem;
transition: transform 0.15s ease;
}

.btn:active {
transform: scale(0.95);

}

.rock {
background-color: gray;
}

.rock:hover {
background-color: rgb(51, 51, 51);
color: white;
}

.paper:hover {
background-color: rgb(192, 192, 192);
}

.scisor {
background-color: rgba(203, 7, 7, 0.719);
}

.scisor:hover {
background-color: red;
}

p {
margin-bottom: 30px;
font-size: 1.8rem;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}

.score {
font-family: 'Black Ops One', sans-serif;
font-variant-numeric: tabular-nums;
position: fixed;
top : 12vh
}

.result {
font-weight: 900;
}


</style>
</head>

<body>
<p class="score"></p>
<p class="result-msg"></p>
<p class="result"></p>
<div class="btn-container">
<button class="btn rock">Rock</button>
<button class="btn paper">Paper</button>
<button class="btn scisor">Scisor</button>
</div>
</body>
<script src="script.js"></script>
</html>
47 changes: 47 additions & 0 deletions Rock paper scisor/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const result = document.querySelector(".result")
const btn = document.querySelectorAll(".btn")
const rock = document.querySelector(".rock")
const paper = document.querySelector(".paper")
const scisor = document.querySelector(".scisor")
const resultMsg = document.querySelector(".result-msg")
const score = document.querySelector(".score")

const choices = ["Rock", "Paper", "Scisor"]

let computerChoice , playerChoice
let playerScore = 0, computerScore = 0

const getComputerChoice = () => {
let i = Math.floor(Math.random() * 3)
return computerChoice = choices[i]
}

const getPlayerChoice = (playerChoice) => {
return playerChoice
}

const displayMessage = () => {
resultMsg.textContent = `Computer choose ${computerChoice}`
}


const playGround = (playerChoice) => {
getComputerChoice()
displayMessage()
if(playerChoice === "Rock" && computerChoice === "Scisor" || playerChoice === "Scisor" && computerChoice === "Paper" || playerChoice === "Paper" && computerChoice === "Rock") {
playerScore++
result.textContent = "You Win :)"
} else if (computerChoice === playerChoice) {
result.textContent = "It's a draw :|"
} else {
computerScore++
result.textContent = "You Lose :("
}
score.textContent = `${playerScore}-${computerScore}`
}

rock.addEventListener("click", () => playGround("Rock"))
paper.addEventListener("click", () => playGround("Paper"))
scisor.addEventListener("click", () => playGround("Scisor"))


22 changes: 22 additions & 0 deletions calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculatrice</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="calculator">
<div class="screen">
<p class="calcul"></p>
<p class="result"></p>
</div>
<div class="keyboard-container">
<div class="keyboard"></div>
</div>
</div>
<script src="script.js"></script>

</body>
</html>
125 changes: 125 additions & 0 deletions calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const keyboard = document.querySelector(".keyboard")
const calcul = document.querySelector(".calcul")
const result = document.querySelector(".result")

const btnElements = ["AC" , "C", "%", "/" ,
"7", "8", "9", "*",
"4", "5", "6", "-",
"1", "2", "3", "+",
"()", "0", "," , "="
]

let addNumber = ""

for (let i=0; i<btnElements.length;i++) {
addNumber += `<button class ="btns btn${i}">${btnElements[i]}</button>`
}
keyboard.innerHTML = addNumber

const btns = document.querySelectorAll(".btns")

let operation = []
const operators = ["+" , "-", "%", "/", "*"]
let operatorIndex = []


let getNumbers = () => {
let numbers = []
let start = 0

for (let a = 0; a < operatorIndex.length; a++) {

let num = operation.slice(start,operatorIndex[a]).join("")

numbers.push(Number(num))

start = operatorIndex[a] + 1
}

let lastNum = operation.slice(start).join("")

numbers.push(Number(lastNum))
return numbers
}



btns.forEach(btn => {
btn.addEventListener("click", () => {
const value = btn.textContent

if (value === "AC" ) {
operation = []
operatorIndex = []
calcul.textContent = ""
result.textContent = ""
console.log(operation)
} else if (value === "C") {
operatorIndex = []
operation.pop()
calcul.textContent = operation.join("")
console.log(operation)
} else if (value === "=") {
getNumbers()
result.textContent = ""
calcul.textContent = calculate()
operatorIndex = []
operation = []
console.log("egal")
} else if (operators.includes(operation.at(-1)) && operators.includes(value)) {
console.log("error")
}

else {
operation.push(value)
calcul.textContent = operation.join("")
console.log(operation)

}

operation.forEach((element, index) => {
if ( operators.includes(element) && !operatorIndex.includes(index)) {
operatorIndex.push(index)
console.log(operatorIndex)
}
})

if (operatorIndex.length > 0 && !operators.includes(operation.at(-1))) {
result.textContent = calculate();
}
})
})






let calculate = () => {
const numbers = getNumbers()
let total = numbers[0]

for (let i = 0; i < operatorIndex.length ; i++) {
const operator = operation[operatorIndex[i]]
const nextNum = numbers[i + 1]

if (operator === "+") total += nextNum;
if (operator === "-") total -= nextNum;
if (operator === "*") total *= nextNum;
if (operator === "/") total /= nextNum;
if (operator === "%") total %= nextNum;
}
return total;

}











96 changes: 96 additions & 0 deletions calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
:root {
--calc-width: min(100vw, 450px);
--key-size: calc(var(--calc-width) * 0.18);
--gap: calc(var(--calc-width) * 0.045);
}

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

.calculator {
height: 100vh;
width: var(--calc-width);
margin: 0 auto;
display: flex;
flex-direction: column;
}

.screen {
width: 100%;
background-color: rgb(0, 0, 0);
flex: 1;
align-items: end;
justify-content: center;
display: flex;
flex-direction: column;
padding-right: 50px;
}

.keyboard-container {
width: 100%;
display: flex;
background-color: black;
padding: 7%;
}

.keyboard {
display: grid;
grid-template-columns: repeat(4,var(--key-size));
grid-auto-rows: var(--key-size);
gap: var(--gap);
justify-content: space-between;


}

.btns {
display: flex;
align-items: center;
justify-content: center;
background-color: blue;
border-radius: 100%;
width: var(--key-size);
height: var(--key-size);
font-size: calc(var(--key-size) * 0.38);
color: white;
background-color: rgb(33, 33, 33);
border: none;
transition: transform 0.15s ease ;
}



.btn0 , .btn1 {
color: red;
}

.btn3,.btn7,.btn11,.btn15 {
background-color: rgb(65, 65, 65);
}

.btn19 {
background-color: rgb(15, 129, 81);
}

.btns:active {
transform: scale(0.95);
}




.calcul {
color: white;
font-size: 2rem;

}

.result {
color: rgba(255, 255, 255, 0.732);
position: relative;
font-size: 1.8rem;
top: 40px;
}
Loading