Create a function that works with arrays

Currently, I have a lottery code that utilizes loops to find and compare numbers in an array. However, I am looking to enhance the program by implementing a function called checkNumber to handle the checking process. This function will require the customer number and the array of winning numbers as arguments. The customer number will be retrieved from getCustomerNumber function, while the array of winning numbers will be obtained from getWinningNumbers function. To display the results, a function called displayResult() will be used. The entire process will be initiated by a function named init. Your assistance with this upgrade is greatly appreciated!

Answer №1

 x = checkNumber(12, 17, 24, 37, 38, 43);

 function checkNumber() {
   for (var i = 0; i < winningNumbers.length && !match ; i++)
  if (winningNumbers[i] == customerNumbers) {
  match = true; 
 }
}

} function getWinningNumbers

function displayResult(){

var message="This week's Winning numbers are:" + "\n" + "\n" + winningNumbers + "\n" + "\n" + "The customer's Number is:" + "\n" + "\n" + customerNumbers + "\n" + "\n" + "We have a match and a winner!";
alert(message)
} Else
var message="This week's Winning numbers are:" + "\n" + "\n" + winningNumbers + "\n" + "\n" + "The customer's Number is:" + "\n" + "\n" + customerNumbers + "\n" + "\n" + "Sorry you are not a winner this week";
alert(message)
}

}

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

Tips for using JSON.stringify in a secure manner

After receiving a JSON object, I convert it to a variable called embed. The console.log output is: console.log(send_me_along) {"provider_url":"https://www.site.com/","description":"Stuff, you’ll need to blah blah","title":"Person detail view & ...

Angular does not select the variable_name within the $scope

Here is the HTML code I have written. <div class="container" ng-app="mintcart"> <div class="panel panel-default" ng-controller="categoriesctrl"> <input type="hidden" ng-model="session.sid" value="<?php echo session_id();?>"/&g ...

Bringing in functions - NodeJS - non-HTML

Currently, I am in the process of learning automation for my job and have hit a roadblock. In times like these, stackoverflow has proven to be a life-saving resource :) My current task involves writing a Selenium test in VisualStudio using JavaScript (nod ...

What is causing the TypeScript error in the MUI Autocomplete example?

I am attempting to implement a MUI Autocomplete component (v5.11) using the example shown in this link: import * as React from 'react'; import TextField from '@mui/material/TextField'; import Autocomplete from '@mui/material/Autoco ...

Insert information into the window before it loads

Exploring the process of opening new windows using JavaScript. var myWindow = window.open(); myWindow.document.write('html'); Is it feasible to inject content into the document before the window fully loads? I aim to include a complete HTML str ...

Trigger a notification from one webpage to another (PHP, JavaScript, HTML)

I'm currently working on a website that consists of both a receptionist page and a user page with multiple logins. The receptionist page displays a table listing all logged-in users, including their status (either ready or busy). This table is refresh ...

Remove a particular item by clicking on the icon in React.js

I'm currently working on a React JS exercise for creating a "To Do List". I am facing an issue where I want to delete individual tasks by clicking the trash icon, but my current code deletes all tasks at once. Can someone help me understand how to ach ...

New and improved method for showcasing the switching of two PHP variables using jQuery Ajax

Obtaining two random values from a table in the same row can be achieved using PHP and MySQL. For example: <?php $result = mysql_query("SELECT * FROM people ORDER BY RAND() LIMIT 1", $connection); $row = mysql_fetch_array($result); echo $ro ...

Is it secure to store the access token within the NextAuth session?

Utilizing a custom API built with Node.js and Express.js, I have implemented nextAuth to authenticate users in my Next.js application. Upon a successful login, the date is stored in the nextAuth session and can be accessed using the useSession hook. To acc ...

Transferring information between two Vue components using a variable declared in the main JavaScript file

In my project, I am working with two separate Vue files - let's say 1.vue and 2.vue - along with a main JS file. Within my main.js file, there is a variable xyz under the window.App data method. I am looking to utilize this variable as a shared data ...

Modifying multiple heading tags simultaneously with jQuery

Currently utilizing jQuery to append a string to all heading tags (h1, h2,..., h6) and display it on the screen. Seeking guidance specifically for the replacing aspect, and open to solutions using plain javascript as well. The code I have so far, which I ...

What are the steps to successfully implement the mail() function in PHP 5.3 from the beginning?

Although I am not entirely new to the world of PHP, I am still trying to navigate my way through it. I create small block websites to test out different features, and currently, I am facing an issue with the mail() function in PHP. Despite looking up solut ...

Run the command "node index.js" to simultaneously start and stop the server

After installing WSL2 and the Ubuntu 22.04 distribution on Windows 11, I set up my environment, installed nvm, Node version 16.17.1, and then ran npm init in my folder. Following that, I installed Express and created an index.js file with a simple structur ...

When using node.js and express, attempting to send an email with the packages 'nodemailer' and 'nodemailer-handlebars' may result in a TypeError being thrown, specifically [ERR_INVALID_ARG_TYPE]

I am encountering an issue while attempting to send an email using an HTML template located in the 'view' folder within the same path. The HTML template is named 'index.handlebars'. Despite believing that the path is correct, I am recei ...

Ways to add elements to the DOM using jQuery from the local storage?

I'm facing a challenge where I have an input field and store the inputs in local storage. When I click on 'add', I want to immediately append the new inputs to my ul element. However, simply appending the current input won't work as it ...

Guide on scheduling MongoDB calls with Node.js recursively

Is there a way to trigger this code or function periodically? I am considering using setInterval, for example: setInterval('function()', 5000);. However, I am unsure about how to implement it in this specific scenario. list = []; MongoClient.conn ...

FullCalendar fails to load in Bootstrap 4 tab

My current project involves utilizing Bootstrap 4 tabs, and I encountered an issue with displaying a FullCalendar on the second tab. Specifically, I am using version 5.2.0 of the FullCalendar library. While the calendar functions correctly when placed on t ...

Unexpected rendering of data retrieved by React

I'm currently facing a challenge with the display of data using ReactJS. Although I can successfully retrieve data from the API and iterate through each object to display individual "products", I'm encountering a problem where each of the thirte ...

Develop and test a query by examining its structure, parsing it, and assessing its effectiveness

Building a query using different conditions selected from html controls in a textarea, allowing users to make modifications as needed. On the client side: a(1, 3) > 20 b(4, 5) < 90 c(3, 0) = 80 The query formed is: a(1, 3) > 20 and b(4, 5) < ...

Function invoking React Hook

I'm a beginner to React JS and I've been learning by working on a project. I was creating a basic e-commerce UI with items and attempting to add items to a cart, but encountered an issue. The React Hook "useStateValue" is being called in the fun ...