JavaScript Exercises Basic#3 - Distributing pencils to the number of students N

JavaScript Exercises Basic#3 - Distributing pencils to the number of students N

You would like to distribute one pencil to each of your students. Write a program which prints how many dozens of pencil you need if there are N numbers of students. (One dozen of pencils equals 12 pencils.)

Solution_1

          /*
            To decide how many dozens I need for the N students, divide N into 12
            If there is a remainder, add 1 to the quotient because there shouldn't be a single student who didn't get a pencil
            The Math.floor() function returns the largest integer less than or equal to a given number, so it will return the quotient
            */

            function solution(N){
                let dozens;
                if (N % 12 === 0) dozens = N / 12;
                else dozens = Math.floor(N / 12) + 1; 

                return dozens;
            }

Result_1

Screenshot 2022-04-12 at 21.10.30.png

Solution_2

          /*
            I could just use Math.ceil() instead
            It will round up the number to the next largest integer if there is a remainder
            */

            function solution(N){
                let dozens = Math.ceil(N / 12);
                return dozens;
            }

Result_2

Screenshot 2022-04-12 at 21.10.30.png