0

The project I'd like to display 9 images (3x3) on a page with dynamic src and change the images by using buttons (Next or previous). Every pictures have 5 tags (ex: sky, new-york, cooking,...) and by chosing a tag every pictures related to this tag will appear.

My problem I don't seems to find the function to force js to go to the next integer as soon as the result of a calcul have decimals so I can't determine the number of pages.

Example of what I'd like to do I want to see all the pictures related to food by clicking on the tag.

numberOfPictures = 9 
numberOfPages = numberOfPictures/9    //number of pages = 1 so I'll display one page

I want to see all the pictures related to traveling by clicking on the tag.

numberOfPictures = 10 
numberOfPages = numberOfPictures/9    //number of pages = 1,111111 so I'll display 2 pages

For the moment I only found a way to get an integer but if the decimals are lower than 5 it get to the lowest integer witch "Hide" some pictures.

Thanks for your time!-Vincent

1 Answers1

3

you can use the Math.ceil function:

const numOfPics = 10

console.log(Math.ceil(numOfPics/9))
Spectric
  • 30,714
  • 6
  • 20
  • 43
LeeLenalee
  • 27,463
  • 6
  • 45
  • 69