samedi 15 avril 2017

3 small issues with functions/random generators (html/javascript)

I'm extremely new to programming, so don't judge my code to harshly. Here's the system that I have going:

In javascript there's this function:

function choreElijah(){

var randoc=Math.round(Math.random()*3);

var doeChore=new Array()

    doeChore[0]="Link goes here";

    doeChore[1]="Link goes here";

    doeChore[2]="Link goes here";

    doeChore[3]="MUSICBUTTONS.html"

    window.location=doeChore[randoc]

};

This function serves to select chores for me to do at random. Here's another:

function elijahMusic(){

var randomus=Math.round(Math.random()*2);

var musicE=new Array()

    musicE[0]="Link goes here";

    musicE[1]="Link goes here";

    musicE[2]="Link goes here";

    window.location=musicE[randomus]

};

The above combination serves to select a piece for me to practice through linking to an html document with "buttons" like the following; these are the same buttons I have in my primary html document:

a href="javascript:choreElijah();"img src="Spicy.png"

The site here didn't like my anchor element for some reason, so I eliminated the brackets.

Which, when clicked, results in the page redirecting to one of the stated links.

I want to do a few things:

  1. I want to have the page redirect to a different tab. I've tried the usual target="_blank", but that doesn't seem to work. I know I usually have the syntax right because that's working with other anchors in my html documents.

  2. I want to weight the possible options, making one chore more likely than another. I'm currently doing this by repeating entries, but can I not just use a range? I've tried something along the lines of doeChore[0

  3. I want to place one of these functions in the other. I'd rather link directly to the music selecting function. I've tried putting elijahMusic() in the place of MUSICBUTTONS.html, but that doesn't seem to work. I suspect that's because a function isn't a link, but if a function isn't a link in any context, then why does this work at all? Do I need to use the "javascript:" preposition?

Sorry for the very lengthy first post, but I really want this thing to work!




Aucun commentaire:

Enregistrer un commentaire