The viralAdvertising() function will set a shared variable to 5 and then loop through the given number of iterations. Each iteration will increase the shared variable by 1/2 and then add the value of the shared variable to the cumulative variable. The last step will set the shared variable to the cumulative variable.
function viralAdvertising(n) {
let shared = 5;
let cumulative = 0;
let liked = 0;
for (let i = 1; i <= n; i++) {
liked = Math.floor(shared / 2);
cumulative += liked;
shared = liked * 3;
}
return cumulative;
}