Multiscreen for lottery javascript









up vote
-1
down vote

favorite












I've been working on this project for a while now. But im stuck on this part. Currently I am making a lottery that generates numbers from 1-99 and you can get a random amount of numbers from 1-10. So what i need help with is making my lottery 2 screens. So when I press generate, it will generate random numbers and I want the number to have its own screen. And then on that screen I want it to show my numbers and have a button that say start again and will bring me back to the main screen. Right now, it only shows my numbers below the textfields.



here are the codes.
JS:



 document.addEventListener("DOMContentLoaded", init);

function init()
document.querySelector("#btnBack").addEventListener("click", toggleSwitch);
document.querySelector("#btnSend").addEventListener("click", generate);

document.addEventListener("keypress", function (e)
if (e.keyCode === 13)
generate();

// console.log(e.keyCode);
);

function toggleSwitch()
pages[0].classList.toggle("active");
pages[1].classList.toggle("active");



let pages = ;
pages = document.querySelectorAll(".page");
let url = "https://davidst.edumedia.ca/mad9014/nums.php";



function reminder()
let dig = document.querySelector("#digits");
let mx = document.querySelector("#max");
if (dig.value <= 0)
alert("Please enter a value for 'number of digits'.nNegative numbers are not accepted.");
dig.focus();
else if (dig.value > 10)
alert("The maximum value is 10. Please check the 'number of digits'");
dig.focus();
else if (mx.value <= 0)
alert("Range must be higher than 0 and lower than 100.");
mx.focus();
else if (mx.value - dig.value < 0)
alert("Lotterys will not accept any duplicates.nTherefore, your range must be higher than 'number of digits'.");
mx.focus();
else if (mx.value > 99)
alert("The highest range is 99.nAny number from 0-99!.");
mx.focus();
else
toggleSwitch();

return;


function generate()
console.log(document.querySelector("#digits").value);
reminder();
let form = new FormData();
let digits = document.querySelector("#digits").value;
let max = document.querySelector("#max").value;
form.append("digits", digits);
form.append("max", max);
let req = new Request(url,
method: "POST",
mode: "cors",
body: form
);

fetch(req)
.then(function (response)
return response.json();
)
.then(function (data)
let numbers = data.numbers;
let ul = document.querySelector(".num_list");
ul.textContent = "";
for (let i in numbers)
let li = document.createElement("li");
li.textContent = numbers[i];
ul.appendChild(li);

console.log(data);
);




html:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AJAX Lotto</title>
<link rel="stylesheet" href="css/main.css" />
</head>

<body>
<div id="home" class="page">
<header>
<h1>$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p class="formBox">
<label for="digits">Number of Digits</label>
<input id="digits" type="number" max="10" min="1" placeholder="6" class="sm" />
</p>
<p class="formBox">
<label for="max">Range</label>
<span>1 to </span><input id="max" type="number" min="2" max="99" placeholder="49" class="sm" />
</p>
<p class="formBox buttons">
<button id="btnSend">Generate Numbers</button>
</p>
</section>
</div>
<div id="list" class="page display">
<header>
<h1 class="color">$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p id="errorMessage"></p>
<ul class="num_list">
<!-- display the generated numbers from the server -->
</ul>
<p>
<button id="btnBack">Start Again</button>
</p>
</section>
</div>
<script src="js/main.js"></script>
</body>
</html>


css



@import url('https://fonts.googleapis.com/css?family=Comfortaa');

h1
font-size: 50px;


html
font-family: 'Comfortaa', serif, sans-serif;
text-align: center;


body
justify-content: center;
margin-top: 5rem;


li
background-color: hsla(10, 0%, 94%, 1);
background-color: hsl(182, 43%, 50%);
border: 5px solid hsl(172, 99%, 20%);
font-weight: bold;
padding: 1.5rem 0;
width: 70px;
margin: 1rem 1rem;
color: hsl(360, 100%, 49%);
font-size: 25px;
background-image: url(lottery-ball-background-vector-55349.jpg);
background-position: center;
background-size: 90px;
border-radius: 20px;
justify-content: center;


ul
text-align: center;
display: flex;
justify-content: center;
list-style-type: none;



button
background-color: hsl(27, 100%, 50%);
border-radius: 10px;
padding: 5px;
border: 2px solid #FEFEFE;
font-size: 25px


@media (max-width:499px)
h1
font-size: 20px;


button
font-size: 10px;


ul
display: inline-block;











share|improve this question























  • How can I make it so that when I press generate only the generated number shows and below that will have a button that says "start again" and when that button is pressed it will bring back to the home screen with the text fields with 1 button that says generate?
    – Zulrahking
    Nov 8 at 20:09














up vote
-1
down vote

favorite












I've been working on this project for a while now. But im stuck on this part. Currently I am making a lottery that generates numbers from 1-99 and you can get a random amount of numbers from 1-10. So what i need help with is making my lottery 2 screens. So when I press generate, it will generate random numbers and I want the number to have its own screen. And then on that screen I want it to show my numbers and have a button that say start again and will bring me back to the main screen. Right now, it only shows my numbers below the textfields.



here are the codes.
JS:



 document.addEventListener("DOMContentLoaded", init);

function init()
document.querySelector("#btnBack").addEventListener("click", toggleSwitch);
document.querySelector("#btnSend").addEventListener("click", generate);

document.addEventListener("keypress", function (e)
if (e.keyCode === 13)
generate();

// console.log(e.keyCode);
);

function toggleSwitch()
pages[0].classList.toggle("active");
pages[1].classList.toggle("active");



let pages = ;
pages = document.querySelectorAll(".page");
let url = "https://davidst.edumedia.ca/mad9014/nums.php";



function reminder()
let dig = document.querySelector("#digits");
let mx = document.querySelector("#max");
if (dig.value <= 0)
alert("Please enter a value for 'number of digits'.nNegative numbers are not accepted.");
dig.focus();
else if (dig.value > 10)
alert("The maximum value is 10. Please check the 'number of digits'");
dig.focus();
else if (mx.value <= 0)
alert("Range must be higher than 0 and lower than 100.");
mx.focus();
else if (mx.value - dig.value < 0)
alert("Lotterys will not accept any duplicates.nTherefore, your range must be higher than 'number of digits'.");
mx.focus();
else if (mx.value > 99)
alert("The highest range is 99.nAny number from 0-99!.");
mx.focus();
else
toggleSwitch();

return;


function generate()
console.log(document.querySelector("#digits").value);
reminder();
let form = new FormData();
let digits = document.querySelector("#digits").value;
let max = document.querySelector("#max").value;
form.append("digits", digits);
form.append("max", max);
let req = new Request(url,
method: "POST",
mode: "cors",
body: form
);

fetch(req)
.then(function (response)
return response.json();
)
.then(function (data)
let numbers = data.numbers;
let ul = document.querySelector(".num_list");
ul.textContent = "";
for (let i in numbers)
let li = document.createElement("li");
li.textContent = numbers[i];
ul.appendChild(li);

console.log(data);
);




html:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AJAX Lotto</title>
<link rel="stylesheet" href="css/main.css" />
</head>

<body>
<div id="home" class="page">
<header>
<h1>$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p class="formBox">
<label for="digits">Number of Digits</label>
<input id="digits" type="number" max="10" min="1" placeholder="6" class="sm" />
</p>
<p class="formBox">
<label for="max">Range</label>
<span>1 to </span><input id="max" type="number" min="2" max="99" placeholder="49" class="sm" />
</p>
<p class="formBox buttons">
<button id="btnSend">Generate Numbers</button>
</p>
</section>
</div>
<div id="list" class="page display">
<header>
<h1 class="color">$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p id="errorMessage"></p>
<ul class="num_list">
<!-- display the generated numbers from the server -->
</ul>
<p>
<button id="btnBack">Start Again</button>
</p>
</section>
</div>
<script src="js/main.js"></script>
</body>
</html>


css



@import url('https://fonts.googleapis.com/css?family=Comfortaa');

h1
font-size: 50px;


html
font-family: 'Comfortaa', serif, sans-serif;
text-align: center;


body
justify-content: center;
margin-top: 5rem;


li
background-color: hsla(10, 0%, 94%, 1);
background-color: hsl(182, 43%, 50%);
border: 5px solid hsl(172, 99%, 20%);
font-weight: bold;
padding: 1.5rem 0;
width: 70px;
margin: 1rem 1rem;
color: hsl(360, 100%, 49%);
font-size: 25px;
background-image: url(lottery-ball-background-vector-55349.jpg);
background-position: center;
background-size: 90px;
border-radius: 20px;
justify-content: center;


ul
text-align: center;
display: flex;
justify-content: center;
list-style-type: none;



button
background-color: hsl(27, 100%, 50%);
border-radius: 10px;
padding: 5px;
border: 2px solid #FEFEFE;
font-size: 25px


@media (max-width:499px)
h1
font-size: 20px;


button
font-size: 10px;


ul
display: inline-block;











share|improve this question























  • How can I make it so that when I press generate only the generated number shows and below that will have a button that says "start again" and when that button is pressed it will bring back to the home screen with the text fields with 1 button that says generate?
    – Zulrahking
    Nov 8 at 20:09












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I've been working on this project for a while now. But im stuck on this part. Currently I am making a lottery that generates numbers from 1-99 and you can get a random amount of numbers from 1-10. So what i need help with is making my lottery 2 screens. So when I press generate, it will generate random numbers and I want the number to have its own screen. And then on that screen I want it to show my numbers and have a button that say start again and will bring me back to the main screen. Right now, it only shows my numbers below the textfields.



here are the codes.
JS:



 document.addEventListener("DOMContentLoaded", init);

function init()
document.querySelector("#btnBack").addEventListener("click", toggleSwitch);
document.querySelector("#btnSend").addEventListener("click", generate);

document.addEventListener("keypress", function (e)
if (e.keyCode === 13)
generate();

// console.log(e.keyCode);
);

function toggleSwitch()
pages[0].classList.toggle("active");
pages[1].classList.toggle("active");



let pages = ;
pages = document.querySelectorAll(".page");
let url = "https://davidst.edumedia.ca/mad9014/nums.php";



function reminder()
let dig = document.querySelector("#digits");
let mx = document.querySelector("#max");
if (dig.value <= 0)
alert("Please enter a value for 'number of digits'.nNegative numbers are not accepted.");
dig.focus();
else if (dig.value > 10)
alert("The maximum value is 10. Please check the 'number of digits'");
dig.focus();
else if (mx.value <= 0)
alert("Range must be higher than 0 and lower than 100.");
mx.focus();
else if (mx.value - dig.value < 0)
alert("Lotterys will not accept any duplicates.nTherefore, your range must be higher than 'number of digits'.");
mx.focus();
else if (mx.value > 99)
alert("The highest range is 99.nAny number from 0-99!.");
mx.focus();
else
toggleSwitch();

return;


function generate()
console.log(document.querySelector("#digits").value);
reminder();
let form = new FormData();
let digits = document.querySelector("#digits").value;
let max = document.querySelector("#max").value;
form.append("digits", digits);
form.append("max", max);
let req = new Request(url,
method: "POST",
mode: "cors",
body: form
);

fetch(req)
.then(function (response)
return response.json();
)
.then(function (data)
let numbers = data.numbers;
let ul = document.querySelector(".num_list");
ul.textContent = "";
for (let i in numbers)
let li = document.createElement("li");
li.textContent = numbers[i];
ul.appendChild(li);

console.log(data);
);




html:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AJAX Lotto</title>
<link rel="stylesheet" href="css/main.css" />
</head>

<body>
<div id="home" class="page">
<header>
<h1>$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p class="formBox">
<label for="digits">Number of Digits</label>
<input id="digits" type="number" max="10" min="1" placeholder="6" class="sm" />
</p>
<p class="formBox">
<label for="max">Range</label>
<span>1 to </span><input id="max" type="number" min="2" max="99" placeholder="49" class="sm" />
</p>
<p class="formBox buttons">
<button id="btnSend">Generate Numbers</button>
</p>
</section>
</div>
<div id="list" class="page display">
<header>
<h1 class="color">$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p id="errorMessage"></p>
<ul class="num_list">
<!-- display the generated numbers from the server -->
</ul>
<p>
<button id="btnBack">Start Again</button>
</p>
</section>
</div>
<script src="js/main.js"></script>
</body>
</html>


css



@import url('https://fonts.googleapis.com/css?family=Comfortaa');

h1
font-size: 50px;


html
font-family: 'Comfortaa', serif, sans-serif;
text-align: center;


body
justify-content: center;
margin-top: 5rem;


li
background-color: hsla(10, 0%, 94%, 1);
background-color: hsl(182, 43%, 50%);
border: 5px solid hsl(172, 99%, 20%);
font-weight: bold;
padding: 1.5rem 0;
width: 70px;
margin: 1rem 1rem;
color: hsl(360, 100%, 49%);
font-size: 25px;
background-image: url(lottery-ball-background-vector-55349.jpg);
background-position: center;
background-size: 90px;
border-radius: 20px;
justify-content: center;


ul
text-align: center;
display: flex;
justify-content: center;
list-style-type: none;



button
background-color: hsl(27, 100%, 50%);
border-radius: 10px;
padding: 5px;
border: 2px solid #FEFEFE;
font-size: 25px


@media (max-width:499px)
h1
font-size: 20px;


button
font-size: 10px;


ul
display: inline-block;











share|improve this question















I've been working on this project for a while now. But im stuck on this part. Currently I am making a lottery that generates numbers from 1-99 and you can get a random amount of numbers from 1-10. So what i need help with is making my lottery 2 screens. So when I press generate, it will generate random numbers and I want the number to have its own screen. And then on that screen I want it to show my numbers and have a button that say start again and will bring me back to the main screen. Right now, it only shows my numbers below the textfields.



here are the codes.
JS:



 document.addEventListener("DOMContentLoaded", init);

function init()
document.querySelector("#btnBack").addEventListener("click", toggleSwitch);
document.querySelector("#btnSend").addEventListener("click", generate);

document.addEventListener("keypress", function (e)
if (e.keyCode === 13)
generate();

// console.log(e.keyCode);
);

function toggleSwitch()
pages[0].classList.toggle("active");
pages[1].classList.toggle("active");



let pages = ;
pages = document.querySelectorAll(".page");
let url = "https://davidst.edumedia.ca/mad9014/nums.php";



function reminder()
let dig = document.querySelector("#digits");
let mx = document.querySelector("#max");
if (dig.value <= 0)
alert("Please enter a value for 'number of digits'.nNegative numbers are not accepted.");
dig.focus();
else if (dig.value > 10)
alert("The maximum value is 10. Please check the 'number of digits'");
dig.focus();
else if (mx.value <= 0)
alert("Range must be higher than 0 and lower than 100.");
mx.focus();
else if (mx.value - dig.value < 0)
alert("Lotterys will not accept any duplicates.nTherefore, your range must be higher than 'number of digits'.");
mx.focus();
else if (mx.value > 99)
alert("The highest range is 99.nAny number from 0-99!.");
mx.focus();
else
toggleSwitch();

return;


function generate()
console.log(document.querySelector("#digits").value);
reminder();
let form = new FormData();
let digits = document.querySelector("#digits").value;
let max = document.querySelector("#max").value;
form.append("digits", digits);
form.append("max", max);
let req = new Request(url,
method: "POST",
mode: "cors",
body: form
);

fetch(req)
.then(function (response)
return response.json();
)
.then(function (data)
let numbers = data.numbers;
let ul = document.querySelector(".num_list");
ul.textContent = "";
for (let i in numbers)
let li = document.createElement("li");
li.textContent = numbers[i];
ul.appendChild(li);

console.log(data);
);




html:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AJAX Lotto</title>
<link rel="stylesheet" href="css/main.css" />
</head>

<body>
<div id="home" class="page">
<header>
<h1>$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p class="formBox">
<label for="digits">Number of Digits</label>
<input id="digits" type="number" max="10" min="1" placeholder="6" class="sm" />
</p>
<p class="formBox">
<label for="max">Range</label>
<span>1 to </span><input id="max" type="number" min="2" max="99" placeholder="49" class="sm" />
</p>
<p class="formBox buttons">
<button id="btnSend">Generate Numbers</button>
</p>
</section>
</div>
<div id="list" class="page display">
<header>
<h1 class="color">$$$ Lotto Numbers $$$</h1>
</header>
<section class="main">
<p id="errorMessage"></p>
<ul class="num_list">
<!-- display the generated numbers from the server -->
</ul>
<p>
<button id="btnBack">Start Again</button>
</p>
</section>
</div>
<script src="js/main.js"></script>
</body>
</html>


css



@import url('https://fonts.googleapis.com/css?family=Comfortaa');

h1
font-size: 50px;


html
font-family: 'Comfortaa', serif, sans-serif;
text-align: center;


body
justify-content: center;
margin-top: 5rem;


li
background-color: hsla(10, 0%, 94%, 1);
background-color: hsl(182, 43%, 50%);
border: 5px solid hsl(172, 99%, 20%);
font-weight: bold;
padding: 1.5rem 0;
width: 70px;
margin: 1rem 1rem;
color: hsl(360, 100%, 49%);
font-size: 25px;
background-image: url(lottery-ball-background-vector-55349.jpg);
background-position: center;
background-size: 90px;
border-radius: 20px;
justify-content: center;


ul
text-align: center;
display: flex;
justify-content: center;
list-style-type: none;



button
background-color: hsl(27, 100%, 50%);
border-radius: 10px;
padding: 5px;
border: 2px solid #FEFEFE;
font-size: 25px


@media (max-width:499px)
h1
font-size: 20px;


button
font-size: 10px;


ul
display: inline-block;








javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 20:18

























asked Nov 8 at 20:08









Zulrahking

12




12











  • How can I make it so that when I press generate only the generated number shows and below that will have a button that says "start again" and when that button is pressed it will bring back to the home screen with the text fields with 1 button that says generate?
    – Zulrahking
    Nov 8 at 20:09
















  • How can I make it so that when I press generate only the generated number shows and below that will have a button that says "start again" and when that button is pressed it will bring back to the home screen with the text fields with 1 button that says generate?
    – Zulrahking
    Nov 8 at 20:09















How can I make it so that when I press generate only the generated number shows and below that will have a button that says "start again" and when that button is pressed it will bring back to the home screen with the text fields with 1 button that says generate?
– Zulrahking
Nov 8 at 20:09




How can I make it so that when I press generate only the generated number shows and below that will have a button that says "start again" and when that button is pressed it will bring back to the home screen with the text fields with 1 button that says generate?
– Zulrahking
Nov 8 at 20:09

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215386%2fmultiscreen-for-lottery-javascript%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215386%2fmultiscreen-for-lottery-javascript%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế