Harumimax/project-lvl1-s482

View on GitHub
src/games/progression.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace BrainGames\games\progression;

use function BrainGames\play\starGame;

const DESCRIPTION = "What number is missing in the progression?";
const LENGTH_OF_PROGRESSION = 10;

function progressionGame()
{
    $getGameData = function () {
        $start = rand(1, 100);
        $step = rand(1, 9);
        $hiddenStep = rand(1, LENGTH_OF_PROGRESSION - 2);
        $progression = [];
        
        for ($i = 0; $i < LENGTH_OF_PROGRESSION; $i++) {
            $progression[$i] = $start + $step * $i;
        }
        
        $correctAnswer = (string)$progression[$hiddenStep];
        $progression[$hiddenStep] = "...";
        $question = implode(' ', $progression);

        return [$correctAnswer, $question];
    };
    
    starGame($getGameData, DESCRIPTION);
}