how to check lottery wining numbers javascript

1.5k views Asked by At

Objective

I wish to query a excel spread sheet to check the numbers entered in the html form are winning numbers.

Winning numbers

winning numbers would be if the first, second, third, fourth fifth, and sixth number entered in the HTML matches the numbers in excel spread sheet in the same row in columns c, d, e, f, h and i.

I have a excel spread sheet called results in my project folder.

Question

Can anyone help me query every row in the spread sheet and print winner or looser if numbers match or not.

My current Code (HTML)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="script.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/alasql/0.4.2/alasql-worker.min.js"></script>
</head>
<body>

<form onsubmit="checkIfYouHaveWinningNumber(); return false;">
    Your numbers:
    <input type="number" name="first"
           min="0" max="100">
    <input type="number" name="second"
           min="0" max="100">
    <input type="number" name="third"
           min="0" max="100">
    <input type="number" name="fourth"
           min="0" max="100">
    <input type="number" name="fifth"
           min="0" max="100">
    <input type="number" name="sixth"
           min="0" max="100">
    <input type="submit">
</form>

</body>
</html>

My current code (JavaScript)

    var data = [{a:3,b:10},{a:2,b:20}];
var lotteryNumbers = alasql('SELECT * INTO XLSX("results") FROM ?',[data]);


function checkIfYouHaveWinningNumber(number)
{
    if(contains(number))
    {
        alert("Congratulation you won - " + number);
    }
    else
    {
        alert("You lose - " + number);
    }
}

function contains(number)
{
    for(var i = 0;i < lotteryNumbers.length;i++)
    {
        if(lotteryNumbers[i] == number)
        {
            return true;
        }
    }
    return false;
}
0

There are 0 answers