How to insert parameter in function

Here I got a function which I need to re run everytime I click button for previous or next. It was working fine but I wanted to refactor my code to use a array object but I don’t know how to insert parameter
following is my code

let count;
 const generateHTML = () => {
    data.images.forEach((el, index)=>{
        viewport.innerHTML = `
             <img class='carousel img-fluid' src="./img/${index}.jpg" alt="">

             <div class="slides">${index +1}</div>
`
})
 }

on next button I want to run generateHTML(count++) and on previous generateHTML(count--)

How can I pass argument so that the Array.forEach has access to it and can increment/decrement index

Just place it between the ().

let count;
 const generateHTML = (newVal) => {
    // you can now use newVal as a variable inside this function
    data.images.forEach((el, index)=>{
        viewport.innerHTML = `
             <img class='carousel img-fluid' src="./img/${index}.jpg" alt="">

             <div class="slides">${index +1}</div>
`
})
 }

but how newVal will increase the index?

I’m not sure I quite understand what you mean

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.