I have this function that is supposed to loop through these addition functions while they won't take the totals up past 100. However, the iteration stops and I need it to finish up with the hunger and danger value either being 100 or 0 depending on which. The numbers that pass through are first: (50,50) second: (0, 100). I can't seem to figure out how to change the addition/subtractions amount when the if condition is no longer met. My consoles are all displaying the last iteration before going over the conditional values.
~~~
function frodo(startingHungerValue, startingDangerValue) {
var shv = startingHungerValue;
var sdv = startingDangerValue;
console.log('startingHungerValue:', shv, 'startingDANGERvalue:', sdv)
return {
dinnerOverFire: () => {
if ((shv >= 0 && shv < 101) && (sdv >= 0 && sdv < 101)) {
return {
hunger: shv - 25,
danger: sdv + 40
}
}
},
hidingInBush: () => {
if ((shv >= 0 && shv < 101) && (sdv >= 0 && sdv < 101)) {
return {
hunger: shv + 35,
danger: sdv - 20
}
}
}
}
}
~~~
Aucun commentaire:
Enregistrer un commentaire