const actualRating = function (num) {
let roundedNum = Math.round(num * 2) / 2;
let string = roundedNum.toString();
let splittedString = string.split('.');
let first = splittedString[0];
let second = splittedString[1];
let biggerSecond = second >= 3 && second <= 5;
let result = [];
if (first == 0 && !biggerSecond) {
result.push('empty empty empty empty empty');
} else if (first == 0 && biggerSecond) {
result.push('half empty empty empty empty');
} else if (first == 1 && biggerSecond) {
result.push('full half empty empty empty');
} else if (first == 1 && !biggerSecond) {
result.push('full empty empty empty empty');
} else if (first == 2 && biggerSecond) {
result.push('full full half empty empty');
} else if (first == 2 && !biggerSecond) {
result.push('full full empty empty empty');
} else if (first == 3 && biggerSecond) {
result.push('full full full half empty');
} else if (first == 3 && !biggerSecond) {
result.push('full full full empty empty');
} else if (first == 4 && biggerSecond) {
result.push('full full full full half');
} else if (first == 4 && !biggerSecond) {
result.push('full full full full empty');
} else if (first == 5 && !biggerSecond) {
result.push('full full full full full');
} else if (first > 5) {
result.push('Avrage Rating greater than 5');
} else {
result.push('Enter a value between 0 and 5 inclusively');
}
return result;
}
console.log(actualRating(0.8));
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.