Friday, March 12, 2021

Sheeps Clothes

This was a neat little coding challenge that encompasses control flow, string interpolation and finding the index of an element.

function warnTheSheep(queue) {
  const wolfIndex = queue.indexOf("wolf")
  const sheepInDanger = (queue.length) - (wolfIndex + 1)
  if (sheepInDanger > 0) {
    return `Oi! Sheep number ${sheepInDanger}! You are about to be eaten by a wolf!`
  } else {
    return "Pls go away and stop eating my sheep"
  }
}

I'm going to try and do more coding challenges in the future and talk about them here. It's a nice way to keep the brain ticking along.