Rearrange the parentheses in a different way specifically for the ternary statement and extract the value of num
without any additional properties.
$scope.msg = 'Ok, you ate ' + num + ' hotdog' + (num > 1 ? 's' : '') + ', got it!';
var num = 1;
console.log('Ok, you ate ' + num + ' hotdog' + (num > 1 ? 's' : '') + ', got it!');
num = 3;
console.log('Ok, you ate ' + num + ' hotdog' + (num > 1 ? 's' : '') + ', got it!');
If you have multiple words for pluralization, consider using an object and function for easier access, like this:
function getPlural(number, word) {
return number === 1 && word.one || word.other;
}
var hotdog = { one: 'hotdog', other: 'hotdogs' },
num = 1;
console.log('Ok, you ate ' + num + ' ' + getPlural(num, hotdog) + ', got it!');
num = 5;
console.log('Ok, you ate ' + num + ' ' + getPlural(num, hotdog) + ', got it!');