[Solved] refactoring/making the code better in javascript [closed]
Yes, you should use switch statement here. Chaining so many else if’s is considered bad practice. You can read about switch statement here. https://www.w3schools.com/js/js_switch.asp Code would look something like: function likes(names) { if(names.length<0) { return `${names} likes this`; //return early if possible } let answer=””; switch (names.length) { case 0: answer = `no one likes … Read more