0
 let e2 = count2 > 2 ? "" : count2 > 5 ? "" : count2 > 8 ? "" : "";
  let e3 = count3 > 2 ? "" : count3 > 5 ? "" : count3 > 8 ? "" : "";
  let e4 = count4 > 2 ? "" : count4 > 5 ? "" : count4> 8 ? "" : "";

In this code user have three input fields where he gives the value of count2,count3,count4 in NUMBER. According to the particular value provided by the user our alogritham returns an emoji.That emoji is based upon how large the value has been given as explained in upper coding.BUT THE THIS ALOGRITHAM ONLY RETURNS THE FIRST AND LAST EMOJI AND NEGLECTS THE EMOJIS IN BETWEEN

Ali Mehdi
  • 47
  • 5
  • 1
    1. extract the repeated logic into a function 2. call the function three times. This saves you two thirds of the code. – VLAZ Sep 21 '22 at 12:07

1 Answers1

2

When you want to repeat some tasks, just use functions.

function countInEmoji(count) {
    if (count === 0) {
        return "";
    } else if (count < 4) {
        return "";
    } else if (count < 6) {
        return "";
    } else {
        return "";
    }
}

count1 = countInEmoji(2);   // 
count2 = countInEmoji(13);  // 
count3 = countInEmoji(6);   // 
Martijn
  • 15,791
  • 4
  • 36
  • 68
Shri Hari L
  • 4,551
  • 2
  • 6
  • 18