I have created a small array called fruits.
what I want to do is if I click the next button web page shows the next value of the array. then if I press the previous button web page shows the previous value of the array
please need your support to short this out.
let fruits=['apple','mango','banana','orange']
let left = document.querySelector('.lef');
let right = document.querySelector('.rig');
let text = document.querySelector('.text');
let crunt=text.innerHTML=fruits[0];
fruits.forEach(element => {
left.addEventListener('click', () => {
text.innerHTML=fruits;
});
});
.btn{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% ,-50%);
display: flex;
gap: 420px;
}
.lef, .rig{
font-size: 70px;
font-weight: 700;
background: none;
border: none;
cursor: pointer;
}
.text{
width: auto;
height: 50px;
font-size: 30px;
background-color: antiquewhite;
display: grid;
place-items: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% ,-50%);
}
<!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">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="btn">
<button class="lef"><</button>
<button class="rig">></button>
</div>
<div class="text"></div>
<script src="script.js"></script>
</body>
</html>