Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Trying to make a slideshow, not behaving as expected

I'm trying to make a slideshow that rotates between images every 5 seconds, or if a button is pressed. If a button is pressed, the slideshow should stop for about 30 seconds (to allow the user to stop and read each slide)

Sorry for noob questions, I'm pretty new to coding

If anyone can help here is my code,

import './App.css';
import pic1 from './images/red.jpg'
import pic2 from './images/green.jpg'
import pic3 from './images/pink.jpg'
import pic4 from './images/blue.jpg'
import * as FaIcons  from "react-icons/fa";
import * as IoIcons  from "react-icons/io5";

var i = 0;
var images = [];
var time = 3000;

images[0] = pic1
images [1] = pic2
images[2] = pic3
images [3] = pic4

function App() {

const [buttonPressedRecently, setPressedRecently]  = React.useState(false);

function changeImage() {
    if (i < images.length - 1){
        i++;
    } else {
        i = 0;
    }
document.getElementById('sponsorImage').src = images [i];
}

function clickedButton() {
  setPressedRecently(true)
  setTimeout(() => {
    setPressedRecently(false)
    console.log(buttonPressedRecently);
  }, 30000);
    changeImage();
  console.log('====================================');
  console.log(buttonPressedRecently);
  console.log('====================================');
}

if (buttonPressedRecently) {
  }
if (!buttonPressedRecently) {
  setInterval(() => {
    changeImage();
  }, 5000);
  }

  return (
    <>

    <div className='Blackbox'>
    <p className='sponsoredText'>Sponsored tokens...</p>
   <button className='nextbtn' onClick={clickedButton}><FaIcons.FaAngleLeft className='arrowicons'/></button>
   <button className='prevbtn' onClick={clickedButton}><FaIcons.FaAngleRight className='arrowicons'/></button>
   <button className='qrbtn'> <IoIcons.IoQrCodeOutline className='arrowicons'/></button>
    <div className='centerline'>

    <img id="sponsorImage" />
   </div>
    </div>
    </>
  );
}

export default App;

I would be delighted if anybody can help. I'm very new to coding

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!