← Back to challenges

The Red/Yellow Sequence

JavaScriptHardalgebramathnumbers

Instructions

Write a function that takes a number n and a string s as arguments and returns the nth term of the Red/Yellow sequence. s will ask the function what to return, all, red or yellow.

alt text

Examples

rySeq(2, "all") ➞ 5

rySeq(3, "yellow") ➞ 8

rySeq(28, "red") ➞ 55

rySeq(1, "blue") ➞ false

Notes

  • If s is not "all", "yellow" or "red", return false.
  • If n is 0, return 0.
  • n is always a positive integer.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.