'Why this() bracket are present in template literal
Hello I am following a Udemy course on java script and have a question about one line of the code
why he applied the bracket () in the template literal after the trophy emoji
console.log(`Dolphins win 🏆 (${avgDolphins} vs. ${avgKoalas})`)
this is the code and the instructions for the exercise.
- Create an arrow function
calcAverageto calculate the average of 3 scores - Use the function to calculate the average for both teams
- Create a function
checkWinnerthat takes the average score of each team as parameters (avgDolhinsandavgKoalas), and then logs the winner to the console, together with the victory points, according to the rule above. Example: "Koalas win (30 vs. 13)". - Use the
checkWinnerfunction to determine the winner for both DATA 1 and DATA 2. - Ignore draws this time.
TEST DATA 1: Dolphins score 44, 23 and 71. Koalas score 65, 54 and 49 TEST DATA 2: Dolphins score 85, 54 and 41. Koalas score 23, 34 and 27
const calcAverage = (a, b, c) => (a + b + c) / 3;
console.log(calcAverage(3, 4, 5));
// Test 1
let scoreDolphins = calcAverage(44, 23, 71);
let scoreKoalas = calcAverage(65, 54, 49);
console.log(scoreDolphins, scoreKoalas);
const checkWinner = function (avgDolphins, avgKoalas) {
if (avgDolphins >= 2 * avgKoalas) {
console.log(`Dolphins win 🏆 (${avgDolphins} vs. ${avgKoalas})`);
} else if (avgKoalas >= 2 * avgDolphins) {
console.log(`Koalas win 🏆 (${avgKoalas} vs. ${avgDolphins})`);
} else {
console.log('No team wins...');
}
}
checkWinner(scoreDolphins, scoreKoalas);
Solution 1:[1]
It's just a part of the logged string, you will see a string like this on the console : " Dolphins win ?(1 vs. 3)".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nabilinfo |
