1var isUgly = function (n) {2let condition = true;3if (n == 0)4// 0 has infinite factors. So checking if the number is 0 or not5return false;6while (condition) {7//applying for true until 2, 3, 5 gets removed from the number8if (n % 2 == 0) n = n / 2;9else if (n % 3 == 0) n = n / 3;10else if (n % 5 == 0) n = n / 5;11else condition = false; //if the number doesnt have 2, 3, 5 in it anymore, this part will execute and will end the while loop12}13return n == 1 ? true : false; //checking if the number only had 2, 3, 5 in it or had something else in it as well14};