Question

[Java Script]

Please help to achieve the result that the question requires below. (My current code is as attached.)

I would like to know how I could tell "If the randomly generated number does not exist in the array, add the number."

Q: The CA SuperLotto Plus lottery game consists of a draw of 6 numbers total.
The first 5 numbers are selected randomly from the same set of numbers
between 1 and 47. This means that you cannot have repeating numbers in this
set of 5.

The Mega number is a single number drawn randomly from the number set
between 1 and 27. This number set is NOT related in any way to the first set.

function draw() { var array1 = []; var i = 0; var x1 = 0; while(i <= 5) { var x1 = Math.floor(Math.random() * 47) + 1; if x1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I am providing the funciton draw():

Code:

<script>
function draw()
{
var array1 = [];
var i=0;
var x1=0,glag =0;
while(i<5)
{
   flag=0;
var x1=Math.floor(Math.random()*47)+1;
for(var k=0;k<i;k++)
   if (array1[k]==x1)
   flag=1; //settting flag=1 when x1 already present in array1
if(flag==0) //if still flag==0 (means x1 not in array1)
{
   array1[i]=x1; //then we are inserting the x1 into array1.
   i++;
}
}
    document.write("Printing the numbers in the array:<br>");
for(var j=0;j<i;j++)
{
   document.write(array1[j]+"<br>");
}
var x2=Math.floor(Math.random()*27)+1;
document.write("\nMeganumber:",x2);   
}
draw();
</script>

Screenshot:

<script> function draw() { var array1 = []; var i=0; var x1=0,glag =0; while(i<5) flag=0; var x1=Math.floor(Math.random()*47)

Output:

Printing the numbers in the array: 33 29 26 27 47 Meganumber:

Hoping that the above answer will help you...Thank you...

Add a comment
Know the answer?
Add Answer to:
[Java Script] Please help to achieve the result that the question requires below. (My current code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • I have the code buts its not working as this below instruction can anyone help Use...

    I have the code buts its not working as this below instruction can anyone help Use the requirements from the pizza part of Assignment 6 and do the following using CSS and an internal style sheet: 1.     Your Javascript function should be in an external file (don’t forget to move it up to studentweb too) 2.     Put a red border of 300px in width around the form 3.     There should be three Div sections: header, main_body, and footer. 4.     Center the name of your...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

  • This is an assignment for my algorithm class which I have written the code partially and...

    This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...

  • please help with all of these questions, thanks. Suppose that diseased trees are distributed randomly and...

    please help with all of these questions, thanks. Suppose that diseased trees are distributed randomly and uniformly throughout a large forest with an average of λ per acre. Let X denote the number of diseased trees in a randomly chosen one-acre plot with range, 0, 1,2,...^ (a) What distribution can we use to model X? Write down its probability mass function (p.m.f (b) Suppose that we observe the number of diseased trees on n randomly chosen one-acre parcels, Xi, X2,...

  • JAVA TIC TAC TOE - please help me correct my code Write a program that will...

    JAVA TIC TAC TOE - please help me correct my code Write a program that will allow two players to play a game of TIC TAC TOE. When the program starts, it will display a tic tac toe board as below |    1       |   2        |   3 |    4       |   5        |   6                 |    7      |   8        |   9 The program will assign X to Player 1, and O to Player    The program will ask Player 1, to...

  • please Question 1 Convert the constraints into linear equations by using slack variables. Maximize z =...

    please Question 1 Convert the constraints into linear equations by using slack variables. Maximize z = 2X1 +8X2 Subject to:X1 + 6x2 s 15 2x1 + 9x2 s 25 X120,X220 X1 + 6x2 +51 s 15 2X1 + 9x2525 25 x1 +6X2+S1 = 15 2X1 +9x2 +52 = 25 O X1 +6X2 + 512 15 2X1 + 9x2 +522 25 X1 +6x2 = S1 +15 2x1 + 9x2 = S2 + 25 Question 2 Introduce slack variables as necessary and...

  • [JS] [HTML] wanting to add this logic to existing code(see below) of a blackjack game, where...

    [JS] [HTML] wanting to add this logic to existing code(see below) of a blackjack game, where it will show the Suit emblem instead of spelled out suit name. example: display 7 ♣ instead of 7 clubs. //this is the logic, main obj is to display suits emblems to existing code if (card.Suit == 'Hearts') icon='&hearts;'; else if (card.Suit == 'Spades') icon = '&spades;'; else if (card.Suit == 'Diamonds') icon = '&diams;'; else icon = '&clubs;'; //existing code blackjack.js //variables for...

  • Hello, I need help with my code. The code needs to display random number from 1...

    Hello, I need help with my code. The code needs to display random number from 1 to 50 every time the program runs but the program displays the same random numbers every time. Thanks #include #include using namespace std; void dynAlloc(int size, int *&arr); void displayArray(int *arr, int n); void insertionSort(int *arr, int n, int *temp); void linear_search(int *arr, int n, int key); void binary_search(int *arr, int n, int key); int main() {   const int n = 50; int *arr,...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT