Erquilenne/project-lvl1-s360

View on GitHub
src/games/Even.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace BrainGames\Even;

use function BrainGames\logic\game;

const DESCRIPTION = 'Answer "yes" if number even otherwise answer "no".';

function run_even()
{
    $getQuestionAndCorrectAnswer = function () {
        $question = mt_rand(1, 999);
        $correctAnswer = isEven($question) ? 'yes' : 'no';
        $question = "{$question}";
        return [$question, $correctAnswer];
    };
    game(DESCRIPTION, $getQuestionAndCorrectAnswer);
}

function isEven($question)
{
    return $question % 2 === 0;
}