Skip to main content

New Project My Counter App - Working on Undo button Still Working

New Project My Counter App - Working on Undo button Still Working 


My Counter Link - https://bhagyeshpro.github.io/mycounter.github.io/


Code JS -

let count = 0;
// select buttons and value
const value = document.querySelector("#value");
const btns = document.querySelectorAll(".btn");
function doUndo (numberIs) {
numberIs = count;
return numberIs;
}
// console.log(btns);
btns.forEach(function (btn) {
btn.addEventListener("click", function(e) {
const styles = e.currentTarget.classList;
// let previous = count;
// console.log(pervious);
if (styles.contains('decrease')) {
count--;
// console.log(count);
}
else if (styles.contains('increase')) {
count++;
// console.log(count);
}
else if (styles.contains('reset')) {
count = 0;
}
else if (styles.contains('ten')) {
count += 10;
}
else if (styles.contains('hundred')) {
count += 100;
}
else if (styles.contains('minten')) {
count -= 10;
}
else if (styles.contains('undo')) {
// count = numberIs();
console.log(numberIs());
// Working ...
}
    if (count > 0) {
        value.style.color = 'green';
    } 
    if (count < 0) {
        value.style.color = 'red';
    }
    if (count == 0) {
        value.style.color = '#222';
    }
value.textContent = count;
})
});

Code HTML -

<!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>Counter App</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<main>
<div class="container">
<h1>My Counter</h1>
<span id="value">0</span>
<div class="button-container">
<button class="btn decrease">decrease</button>
<button class="btn reset">reset</button>
<button class="btn increase">increase</button>
</div>
<div>
<button class="btn ten">+ 10</button>
<button class="btn hundred">+ 100</button>
<button class="btn minten">- 10</button>
</div>
<div>
<!-- <button class="btn undo">undo</button> -->
</div>
<div>
</div>
</main>
<script src="app.js"></script>
</body>
</html>


Code CSS -

body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: aliceblue;
}
.container h1 {
font-family: Georgia, 'Times New Roman', Times, serif;
font-size: 2rem;
}
.container {
text-align: center;
}
span {
font-size: 7rem;
color:black;
}
.btn {
font-family: Georgia, 'Times New Roman', Times, serif;
background: transparent;
letter-spacing: 0.1rem;
font-size: 1rem;
font-weight: 400;
transition: all 0.3s linear;
border-radius: 0.4rem;
border: 2px solid #222;
display: inline-block;
cursor: pointer;
margin-left: 0.3rem;
padding: 0.25rem 0.75rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
margin-bottom: 0.7rem;
}
.btn:hover {
color: whitesmoke;
background: black;
transform: scale(1.1);
}
.links {
display: flex;
}
.links h3 {
margin-top: 7rem;
}
.clickMe {
font-family: Georgia, 'Times New Roman', Times, serif;
background: transparent;
letter-spacing: 0.1rem;
font-size: 1rem;
font-weight: 400;
transition: all 0.3s linear;
border-radius: 0.4rem;
border: 2px solid #222;
display: inline-block;
cursor: pointer;
margin-left: 0.3rem;
padding: 0.25rem 0.75rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
margin-bottom: 0.7rem;
}
.clickMe:hover {
color: whitesmoke;
background: #A52A2A;
transform: scale(1.1);
}

Comments

Popular posts from this blog

Topic Learned!

 Topic Learned! State : State is updated whenever user want to update it. Example : ToDo List Props:           Props would be whatever the current state is! useEffect:            componentDidMount() {             // Run This code while the app is loading          Example fetchUser();      } Alternative For componentDidMount(): In functional components    //On Every Render   useEffect (() => {     console . log ( "I re-rendered" );   }); Alternative For componentDidMount() but runs only in first Render: //On First Render/Mount - componentDidMount   useEffect (() => {     console . log ( "Component Is Mounted" );   }, []); Alternative for componentDidUpdate(): //On First Render + whenever the component changes   //componentDidUpdate alternative   useEffect (() => {   ...

React Native Full Notes

React Native Full Notes Device Orientation Like Youtube - First Go To App.json and set orientation:: "default"; Then go to project folder and run npm i @react-native-community/hooks import  {  }  from   'expo-status-bar' ; import   React   from   'react' ; import  {  Dimensions ,  StyleSheet ,  SafeAreaView ,  Text ,  View ,  Button ,  Platform ,  StatusBar  }  from   'react-native' ; import  {  useDimensions ,  useDeviceOrientation  }  from   "@react-native-community/hooks" ;   export   default   function   App () {    const  {  landscape  } =  useDeviceOrientation ();    return  (      < SafeAreaView   style = { styles . container } >        < View   style = { {          backg...

Linux Basics Cmd

  Install Package      sudo apt update     sudo apt install discord (Error_?)     sudo apt --fix-broken install  Remove Packages:     sudo apt remove firefox-esr (remove without deleting user data)     sudo apt purge firefox-esr (remove all user data) Update & upgrade :     sudo apt update && sudo apt upgrade     dpkg -l (List insatllled packages)