mardi 27 octobre 2015

Need help translating simple Python script to JavaScript

Can somebody please help me make this Python code (that randomly selects an item from a dictionary) into JavaScript! Must be automatically scaleable to any dictionary length.

from random import choice
songs = {
    "Link":"AlbumArt","Link2":"AlbumArt2"
}
random_item = choice(list(songs.keys()))
link = random_item
art = songs[random_item]
print(link,art)


Can you please also make it so that it executes when an html button is pressed and instead of saving to variables, it replaces the "Link" with the src of an iframe tag and "AlbumArt" with the src of an img tag. Sorry if I'm not being too specific here, It doesn't really matter what the specifics are as long as it fits that general category. It also must be able to pick a random thing in a dictionary of any length, as I will be adding more things to the songs dictionary in the future!




Aucun commentaire:

Enregistrer un commentaire