File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22< html lang ="en ">
33< head >
44< meta charset ="UTF-8 ">
5- < title > Simple Clicker Game</ title >
5+ < title > Clicker Game</ title >
66< style >
77 body {
88 font-family : Arial, sans-serif;
1111 color : white;
1212 margin-top : 60px ;
1313 }
14- # button {
14+ # clickButton {
1515 padding : 25px 50px ;
1616 font-size : 24px ;
1717 background : # 4CAF50 ;
2121 cursor : pointer;
2222 transition : transform 0.1s ;
2323 }
24- # button : active {
24+ # clickButton : active {
2525 transform : scale (0.95 );
2626 }
27+ # upgradeButton {
28+ margin-top : 20px ;
29+ padding : 15px 30px ;
30+ font-size : 18px ;
31+ background : # 1E90FF ;
32+ border : none;
33+ border-radius : 12px ;
34+ color : white;
35+ cursor : pointer;
36+ }
37+ # upgradeButton : disabled {
38+ background : gray;
39+ cursor : not-allowed;
40+ }
2741</ style >
2842</ head >
2943< body >
3044
3145< h1 > Clicker Game</ h1 >
3246< h2 > Clicks: < span id ="score "> 0</ span > </ h2 >
3347
34- < button id ="button "> Click Me!</ button >
48+ < button id ="clickButton "> Click Me!</ button >
49+
50+ < h3 > Upgrade</ h3 >
51+ < button id ="upgradeButton " disabled > Upgrade Click (+1) – Cost: 50</ button >
3552
3653< script >
3754 let score = 0 ;
55+ let clickPower = 1 ;
56+ let upgradeCost = 50 ;
57+
58+ const scoreEl = document . getElementById ( "score" ) ;
59+ const clickButton = document . getElementById ( "clickButton" ) ;
60+ const upgradeButton = document . getElementById ( "upgradeButton" ) ;
61+
62+ clickButton . addEventListener ( "click" , ( ) => {
63+ score += clickPower ;
64+ update ( ) ;
65+ } ) ;
3866
39- document . getElementById ( "button" ) . addEventListener ( "click" , ( ) => {
40- score ++ ;
41- document . getElementById ( "score" ) . textContent = score ;
67+ upgradeButton . addEventListener ( "click" , ( ) => {
68+ if ( score >= upgradeCost ) {
69+ score -= upgradeCost ;
70+ clickPower ++ ;
71+ upgradeCost = Math . floor ( upgradeCost * 1.5 ) ;
72+ upgradeButton . textContent = `Upgrade Click (+1) – Cost: ${ upgradeCost } ` ;
73+ update ( ) ;
74+ }
4275 } ) ;
76+
77+ function update ( ) {
78+ scoreEl . textContent = score ;
79+ upgradeButton . disabled = score < upgradeCost ;
80+ }
4381</ script >
4482
4583</ body >
You can’t perform that action at this time.
0 commit comments