Assignment:Super Lotto
This exercise is JavaScript only. No jQuery, please. Your page
should work as follows:
Ask the user the highest number that they want to generate. (Some
lotteries are 1 ‐ 47, some 1 ‐ 49, etc.)
Ask the user how many numbers they want to generate.
Create a function that returns a random number between 1 and the highest number (see "Additional Info" below).
Create an array of numbers. Run the function the correct number
of times, putting a random number in each place in the array. Print
the array.
Additional Info
1. The code below will return a random number between 1 and 10. Note that our code will be a bit different, since our number is not between 1 and 10.
Math.floor(Math.random() * 10) + 1
More info on this is available here: https://www.w3schools.com/js/js_random.asp
2. One way to make an array into a string (for printing) is to use the join method. The code below will put the elements of an array into a string, separated by the separator. array.join(separator)
More info on this is available here: https://www.w3schools.com/jsref/jsref_join.asp
Please see bellows the screenshots for what this output should look like. You should try to match the way the numbers are displayed.
3. Note that there is some CSS already created to help with the formatting of the generated numbers. See the "boxed" class in lotto‐styles.css. When you are finished, view your page in a browser. It should look like and work like below pictures, (but of course your numbers will be different).
Extra Credit (10 points)
In a real lottery, no two numbers are repeated. Save your file as lotto‐ec.html. Modify the code so that the numbers are not duplicated.
----------------------------------------------------------------------------------------------------------------
Add the necessary code (JavaScript, HTML, and/or CSS) to generate a set of lotto numbers.
// lotto.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Super Lotto</title>
<meta charset="utf-8">
<link
href="https://fonts.googleapis.com/css?family=Libre+Franklin"
rel="stylesheet">
<link href="lotto-styles.css" rel="stylesheet">
/head>
<body>
<div id="container">
<header>
<h1>Lucky Numbers</h1>
</header>
<main>
<p>Good luck!</p>
</main>
</div> <!-- Closing container -->
</body>
</html>
--------------------------------------------------------------------------------------------------
// lotto-styles.css
body {
font-family: 'Libre Franklin', sans-serif;
}
#container {
width: 80%;
background-color: #dee6ca;
min-height: 500px;
margin: 0 auto;
padding: 10px;
text-align: center;
}
.boxed {
padding: 15px;
width: 40%;
border: 2px solid #000000;
background-color: #FFFFFF;
margin: 0 auto;
color: #2f9a00;
font-size: 1.5em;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Super Lotto</title>
<meta charset="utf-8">
<link
href="https://fonts.googleapis.com/css?family=Libre+Franklin"
rel="stylesheet">
<link href="lotto-styles.css" rel="stylesheet">
</head>
<body>
<div id="container">
<header>
<h1>Lucky Numbers</h1>
</header>
<div class="boxed" id="ans">
Your numbers are:
</div>
<main>
<p>Good luck!</p>
</main>
</div> <!-- Closing container -->
<script type="text/javascript">
//function checks if a is in arr or
not
function find(a, arr)
{
//if found
return false
for (var i = 0;
i < arr.length; i++) {
if(arr[i] == a)
return false;
}
//if not found,
return true
return
true;
}
function getRandomNumber(arg, arr)
{
do{
var a = Math.floor(Math.random() * arg) +
1;
//if generated random number is not in arr
//then we return a
//else loop continues.
if(find(a, arr))
{
return a;
}
}while(true);
}
//reading vlaues
var highestNum =
parseInt(prompt("What's the highest number?"));
var count = parseInt(prompt("How
many numbers do you want?"));
var arr = new Array(count);
//pupulating array.
for (var i = 0; i < arr.length;
i++) {
arr[i] =
getRandomNumber(highestNum, arr);
}
//showing array
document.getElementById('ans').innerHTML += arr.join(" * ");
</script>
</body>
</html>
Assignment:Super Lotto This exercise is JavaScript only. No jQuery, please. Your page should work as follows: Ask the user the highest number that they want to generate. (Some lotteries are 1 ‐ 47, so...