Back to Freecodecamp

Challenge 242: Next Bingo Number

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69b58ce40693f140c84c855b.md

latest1.4 KB
Original Source

--description--

Given a bingo number, return the next bingo number sequentially.

A bingo number is a single letter followed by a number in its range according to this chart:

LetterNumber Range
"B"1-15
"I"16-30
"N"31-45
"G"46-60
"O"61-75

For example, given "B10", return "B11", the next bingo number. If given the last bingo number, return "B1".

--hints--

getNextBingoNumber("B10") should return "B11".

js
assert.equal(getNextBingoNumber("B10"), "B11");

getNextBingoNumber("N33") should return "N34".

js
assert.equal(getNextBingoNumber("N33"), "N34");

getNextBingoNumber("I30") should return "N31".

js
assert.equal(getNextBingoNumber("I30"), "N31");

getNextBingoNumber("G60") should return "O61".

js
assert.equal(getNextBingoNumber("G60"), "O61");

getNextBingoNumber("O75") should return "B1".

js
assert.equal(getNextBingoNumber("O75"), "B1");

--seed--

--seed-contents--

js
function getNextBingoNumber(n) {

  return n;
}

--solutions--

js
function getNextBingoNumber(n) {
  const num = parseInt(n.slice(1));
  const next = num === 75 ? 1 : num + 1;

  if (next <= 15) return "B" + next;
  if (next <= 30) return "I" + next;
  if (next <= 45) return "N" + next;
  if (next <= 60) return "G" + next;
  return "O" + next;
}