Row Bot explainer


#1

The aim of this puzzle: Check if the row string has three Os in a row.

Walkthrough of the solution: The row is a string with 10 random letters, each one is either 'X' or 'O'. The row represents a row of seats, and each one is either taken ('X') or open ('O').

To see if there are 3 open seats next to eachother, the row string would need to contain 'OOO' somewhere in it. The .includes() method searches the string and returns either true or false.

In the 2nd If Statement, the test is row.includes('X'). That would check if there is any seat that is taken. The 'X' should be changed into 'OOO' to check if there are 3 seats side by side.

Sample code solution:
(Tap below to reveal)

console.log(row);
if (row.includes('O')) {
  console.log('There is an open seat.');
}

if (row.includes('OOO')) {
  console.log('There are 3 seats together.');
}

JavaScript Concepts: console.log(), If Statements, .includes()