JavaScript-Powered Lotte Online Game

Just dipping my toes into the world of Javascript. I'd appreciate any help you can offer as I dive into creating a Lotte web game.

  1. Step one: Determine the number of participants
  2. Step two: Choose a number

The objective is to:

Select the number of participants from the table below and then choose the corresponding number in the [select option box]. For example, if there are 5 participants, select number 5. Upon clicking the submit button, random players will be displayed with their names and numbers.

Example: David-1, Jane-5, July-3, Michale-2, John-4

'use strict';

function initiate() {

  const members = document.querySelectorAll('input[type="checkbox"]:checked');
  const hitNum = +document.querySelector('select[name="hit"]').value;
  const missNum = +document.querySelector('select[name="miss"]').value;

  if (members.length > hitNum + missNum) {
    alert("Not enough lottery tickets.");
    return;
  }

  const lotArr = ('1'.repeat(hitNum) + '0'.repeat(missNum)).split('');
  const result = [
    [],
    []
  ];

  for (const e of members) {
    const rnd = Math.floor(Math.random() * lotArr.length);
    const pickup = lotArr.splice(rnd, 1)[0];

    result[pickup].push(e.value);
  }

  document.querySelector('#result h3:first-child').textContent = 'Winners:' + result[1].join();

}
.wrapper {
  margin: 50px 10%;
  text-align: left;
}

body {
  background: #6B92B9;
}

.area {
  width: 80%;
  margin: 0 auto;
}

table {
  width: 100%;
}

table,
th,
td {
  border: 1px solid black;
  border-collapse: collapse;
}

th,
td {
  padding: 15px;
  text-align: left;
}

#t01 tr:nth-child(even) {
  background-color: #eee;
}

#t01 tr:nth-child(odd) {
  background-color: #fff;
}

#t01 th {
  background-color: #6c79e0;
  color: white;
}

h2 {
  display: block;
  font-size: 1.5em;
  margin-top: 0.83em;
  margin-bottom: 0.83em;
  margin-left: 0;
  margin-right: 0;
  font-weight: bold;
  margin-left: 250px;
}

#member {
  margin: 5px auto 20px;
}

#member label {
  display: inline-block;
}

#lottery-numbers {
  margin: 0 auto 20px;
}

.button {
  border-bottom: solid 1px #000;
  padding: 0 0 20px;
  margin: 0 auto 50px
}

#result h3 {
  font-size: 18px;
  font-weight: bold;
  color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="wrapper">
  <div class="area">
  
    <div id="member">
    
      <h2>Let's select the participants!:</h2>

      <div id="lottery-numbers">
      
        <h2>Number of lottery tickets:</h2>
        
        Winners:
        <select name="hit">
          <option value="1" selected>1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
        </select>
        
        Tickets:
        <select name="miss">
          <option value="1" selected>1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
        </select><br>
        
      </div>
      
      <div class="button" style="text-align: center;">
        <input type="button" value="Start Lottery" onclick="initiate();">
      </div>
      
      <div id="result">
        <h3>Winners:</h3>
      </div>
      
    </div>

    <table id="t01">
    
      <tr>
        <th>Sales Division</th>
        <th>Marketing</th>
        <th>Administration</th>
        <th colspan="2" style="text-align: center;">Production Division</th>
        <th>PART</th>
      </tr>
      
      <tr>
        <td><label><input type="checkbox" value="A" checked/>A</label></td>
        <td><label><input type="checkbox" value="B" checked/>B</label></td>
        <td><label><input type="checkbox" value="C" checked/>C</label></td>
        <td><label><input type="checkbox" value="D" checked/>D</label></td>
        <td><label><input type="checkbox" value="E" checked/>E</label></td>
        <td><label><input type="checkbox" value="F" checked/>F</label></td>
      </tr>>
      
      <!-- More rows of checkboxes go here -->
      
    </table>

  </div>
</div>

Answer №1

Your inquiry lacks specifics, therefore to introduce randomness into the outcomes, consider implementing a code snippet similar to the following:

result[pickup].push(e.value + Math.floor(Math.random() * lotArr.length));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring canvas element via socket with JS stack size limit

I'm encountering an issue where I need to transfer a canvas element over sockets using socket.io and Node.js. The code snippet below illustrates my approach: var myCanvas = document.getElementById("myCanvas"); var ctx = myCanvas.getContext("2d"); // ...

Is it possible to include more than one ng-app directive on a single HTML page in AngularJS?

When working with Angular JS, I've noticed that I only get the desired output if I remove either the ng-app directive for demo1 or the models. It seems like having two ng-app directives active at the same time causes issues. As a beginner in Angular J ...

Exploring the realm of unit testing in the NestJS CQRS architecture journey

We're currently working on writing unit tests using Jest for our application and are facing difficulties in testing sagas. Specifically, we're having trouble testing the saga itself. During our unit testing process, we've encountered an iss ...

Discovering the URL of an AJAX request on any given website

Is there a way to retrieve the URLs of AJAX requests that are sent by the current page on a website using a browser or another tool? ...

"The server responded with a 405 error message indicating that the requested method

I have been working on a registration form project using HTML, JS, NodeJS, and SQLite. However, I am encountering an issue with the fetch function when trying to post the inputted information into the database. I keep receiving a POST 405 (Method Not Allo ...

What is the process for sending a form using Ajax and then showcasing the form details through a popup notification?

I need to create a form that, when submitted, displays an alert with the information entered in the form. The alert should show the message: "Your FirstName is Mickey and LastName is Mouse!" <!DOCTYPE html> <html> <head> <script ...

Guide on manipulating the position and orientation of external elements in three.js

I'm currently working on a small project that involves creating an interactive 3D scene on the web. To achieve this, I utilized three.js to import objects designed in Blender. Initially, I attempted to export the objects as JSON files, but encountered ...

Why is Selenium failing to retrieve the contents of a class?

PATH = "D:\CDriver\chromedriver.exe" driver = webdriver.Chrome(PATH) driver.get('https://www.se.com/ww/en/about-us/careers/job-details/inside-sales-associate/006ZMV') TITLE = driver.find_element_by_class_name('sdl-applica ...

Guide to parsing JSONP information using Express

I am attempting to transfer data from phonegap to an express application. Below is the code I am using: Phonegap: $.ajax({ type: 'POST', url:"http://127.0.0.1:3000/test", data: {"test":"this works!"}, dataTyp ...

Unleashing the Power of Resetting CSS Class Attributes in Twitter Bootstrap

Last year, @Andres Ilich shared a remarkably elegant solution for centering the navigation bar in Bootstrap. Here is an excerpt from the answer he posted: Visit here for more details. <div class="navbar navbar-fixed-top center"> <div class=" ...

Modify the positioning of images in HTML based on window resizing

Trying to solve this problem seems more complicated than it actually is. I have 6 Images, each accompanied by a button below. Here's an example of what I'm working with: https://i.sstatic.net/sYCgC.png The way I currently have them set up is li ...

Ways to select the initial 10 rows, final 3 rows, and middle 2 rows using Javascript

As a newcomer to Javascript, I have a couple of questions: 1) How can I retrieve the first 10 rows, the last 3 rows, and the 2 rows in the center using the code var firstTable = $('#aaa table').eq(0); 2) Is there a way to create and assign new ...

Activate the Dart checkbox to ensure it is checked

Is there a way to programmatically check a CheckBox element? I've attempted using Click();, but it hasn't worked. I've also looked for a method like .setChecked(true); without any luck. Could it be because I'm utilizing the checkbox as ...

Encountered an error while attempting to log in: TypeError: the property 'id' of null cannot be read

I am facing an issue with the login process, specifically getting a TypeError: Cannot read property 'id' of null error message. How can I debug and resolve this error? var cas = require('cas-client'); get_forward_url(function(forwardur ...

What could be causing my Bootstrap 5 hover effect to malfunction?

Can anyone help with changing the hover effect of a bootstrap button in my code? Here's the HTML: <button type="button" class=" btn btn-dark">Sign Up</button> And here's the CSS I tried: .btn-dark:hover { color: ...

Error in content policy for CSS in Stripe Checkout

I am currently attempting to integrate Stripe Checkout into my Ionic App. I have created a Directive that injects the form into my content view, however, upon execution, the CSS fails due to a content policy violation: checkout.js:2Refused to load the s ...

An advanced template system incorporating dynamic scope compilation

My project requires a unique solution that cannot be achieved with standard data-binding methods. I have integrated a leaflet map that I need to bind with a vue view-model. While I was able to display geojson features linked to my view, I am facing chall ...

Is it possible to align the navigation within the Bootstrap (5) grid structure like I have shown in my example?

Can this be achieved? Any tips on how to do it while sticking within the Bootstrap framework would be greatly appreciated. Text blocks should align with the navigation border on the left and right side: <link rel="stylesheet" href="https://cdn.jsd ...

Every time a new message is sent or received, I am automatically brought back to the top of the screen on the

I'm currently working on integrating a chat feature into my Angular Firestore and Firebase app. Everything seems to be functioning well, except for one issue - whenever a new message is sent or received, the screen automatically scrolls up and gets st ...

How can we find the variance between each value in an array using JavaScript?

Here is the data set provided. It consists of an array of objects with different properties: [{ createdAt: Wed Feb 08 2017 12:16:35 GMT+0500 (Pakistan Standard Time), set: 'jr', },{ createdAt: Wed Feb 08 2017 12:18:36 GMT+0500 (Pak ...