Skip to content

Commit 50007e3

Browse files
committed
randomized button
1 parent 53b3fa6 commit 50007e3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

FrontendTemplate/separate-component/src/components/GutiButton.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,31 @@ const GutiButton = () => {
1010
const [showButton, setShowButton] = useState(true);
1111
const [showImage, setShowImage] = useState(false);
1212
const [selectedButton, setSelectedButton] = useState(null);
13+
const [shuffledArray, setShuffledArray] = useState([police, babu, chor, dakat]);
1314

1415
const imageArray = [police, babu, chor, dakat];
15-
const myguti = 2;
16+
1617

1718
// const buttonClicking = () => {
1819
// setShowButton(false);
1920
// setShowImage(true);
2021

2122
// };
23+
const shuffleArray = (array) => {
24+
let newArray = array.slice(); // Create a copy of the original array
25+
for (let i = newArray.length - 1; i > 0; i--) {
26+
const j = Math.floor(Math.random() * (i + 1));
27+
[newArray[i], newArray[j]] = [newArray[j], newArray[i]];
28+
}
29+
return newArray;
30+
};
31+
const myArray = shuffleArray(imageArray);
32+
console.log(myArray);
33+
const myguti= 0;
34+
2235

2336
const buttonClicking = (index) => {
37+
setShuffledArray(shuffleArray(shuffledArray));
2438
setShowButton(false);
2539
setShowImage(true);
2640
setSelectedButton(index);
@@ -43,7 +57,7 @@ const GutiButton = () => {
4357
{showImage && selectedButton === index && (
4458
<img
4559
id='shah'
46-
src={imageArray[myguti]}
60+
src={myArray[myguti]}
4761
alt="Displayed Image"
4862
/>
4963
)}
@@ -96,6 +110,7 @@ img{
96110
#shah{
97111
height: 400px;
98112
width: 400px;
113+
99114
}
100115
101116

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy