# i'm having trouble Mock lottery ticket mailer

## Recommended Posts

Hello,

I am wondering if someone could take a look at this javascript rule and help me figure out to be able to generate a mock ticket of 12 slots with prizes.

Here are the prizes

3 Gold Pot (graphic image)

6 \$20

1 \$25

1 \$50

1 \$75

Those prizes have to be random and the mailer is a 3 panel brochure where the ticket is one of the panels. So I will have to possibly have two lists in it. You can only scratch-off one slot to win however.

Here is the Rule:

var twentycount : int = 0;// keeps track of how many times you add \$20 to one of the slots

var potcount : int = 0; // keeps track of how many times you add a gold pot to one of the slots

var twentyfivecount : int = 0; // keeps track of how many times you add \$25 to one of the slots

var fiftycount : int = 0; // keeps track of how many times you add \$50 to one of the slots

var seventyfivecount : int = 0; // keeps track of how many times you add \$75 to one of the slots

// keep adding counts to keep track of how many times you want to add a prize

var size : int = 0; // this is the number of slots you need to fill. Once it hits zero, we stop the loop

var roll : int; // this is the variable that holds the random value

var slots = [] // this will be your list of the 12 slots where you put the prizes

// this is a loop that executes 12 times (putting 12 prizes in each of the slots)

while(size < 12){ // while size does not equal 12. We will add 1 to size whenever we put a prize in the slot list

roll = Math.floor(Math.random()*4) // picks a number between 0 and 4

// Math is the class for which the function random() is located in

// multiply random() in order to increase the range. In this case, 0 to 5

// Math.floor means that it truncates the decimal off. So 4.75 becomes 4

// If we roll a 0, then we put \$20 into one of the slots

if(roll == 0 && twentyCount < 6){ // if random picks 0 and we didn't exceed the amount of \$20 we can put

// this is where you add your image of \$20 for example

slots = "\$20" // or whatever image you want to put (I don't know how to do the images)

twentyCount = twentyCount + 1;

size = size + 1;}

// If we roll a 1, then we put gold pot into one of the slots

if(roll == 1 && potCount < 3){ // if random picks 1 and we didn't exceed the amount of gold pots we can put

slots = "Gold Pot" // or whatever image you want to put (I don't know how to do the images)

potCount = potCount + 1;

size = size + 1;}

if(roll == 2 && twentyFiveCount < 1){ // if random picks 2 and we didn't exceed the amount of \$25 we can put

// this is where you add your image of \$25 for example

slots = "\$25" // or whatever image you want to put (I don't know how to do the images)

twentyCount = twentyCount + 1;

size = size + 1;}

if(roll == 3 && fiftyCountCount < 1){ // if random picks 3 and we didn't exceed the amount of \$50 we can put

// this is where you add your image of \$50 for example

slots = "\$50" // or whatever image you want to put (I don't know how to do the images)

twentyCount = twentyCount + 1;

size = size + 1;}

if(roll == 4 && seventyFiveCount < 1){ // if random picks 4 and we didn't exceed the amount of \$75 we can put

// this is where you add your image of \$75 for example

slots = "\$75" // or whatever image you want to put (I don't know how to do the images)

twentyCount = twentyCount + 1;

size = size + 1;}

}

for(int i = 0; i < 12; i++){

if(slots == "\$20")

// add graphics for \$20 to whatever position the i-th box is

else if(slots == "Pot of Gold.tif")

// add graphics for the gold pot to whatever position the i-th box is

else if(slots == "\$25")

// add graphics for \$25 to whatever position the i-th box is

else if(slots == "\$50")

// add graphics for \$50 to whatever position the i-th box is

else if(slots == "\$75")

// add graphics for \$75 to whatever position the i-th box is

}

// To refresh, Math.random() picks a number between 0 and 1, including decimals. Since you don't want decimals,

// makes sure you apply the floor function to random() by doing this Math.floor(Math.random()), that way it

// just cuts off the decimal part.

// I made sure that the loop doesn't stop until you fill up all 12 slots. The only way we can fill it all up

// is if it reaches one of the rolls. Therefore, the size increases by 1 and we roll again. It stops once

// size reaches the value of 12. Because you have EXCEL files and lists, I don't know how to integrate that

// stuff.

// You can apply those if-statement blocks to other prizes. Just make sure there's a cap by adding a counter

// variable at the top.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• #### FusionPro.com

• MarcomCentral
×
• Create New...