this is the log
console.log(duckShoot(4, 0.64, '|~~2~~~22~2~~22~2~~~~2~~~|'));
the output must be====>|~~X~~~X2~2~~22~2~~~~2~~~|
here the code i've try:
function duckShoot(ammo, aim, ducks) {
let shot = Math.floor(ammo * aim)
// console.log(shot);
return ducks.replace (/2/g, "X")
}
how to make /2/g just replace certain repeating
i wanna make code above same function with this
function duckShoot(ammo, aim, ducks) {
let shot = Math.floor(ammo * aim)
// console.log(shot);
for (let i = 1; i <= shot; i++) {
ducks = ducks.replace("2", "X");
}
return ducks
}