nonono
nonono

Reputation: 601

Getting jquery to show respective text

I have a quote machine which displays random movie quotes. Now I'm trying to add the name of the movie underneath the quote using jquery but it's not working for some reason. I tried following what others have done on their own quote machine projects or modifying snippets in my own code but I can't seem to figure it out.

Code I've tried:

function getQuote() {
        var randomIndex = Math.floor(Math.random() * quotes.length);
        var selectedQuote = quotes[randomIndex];

        $('#main-quote').text(selectedQuote.quote);
        var selectedBG = selectedQuote.background;
        console.log(selectedBG);
        $("body").css("background-image", "url('" + selectedBG + "')");

        $('#main-quote').text(selectedQuote.quote);
        var selectedMovie = selectedQuote.movie;
        console.log(selectedMovie);
        $("#what-movie").html("selectedMovie");
    }

Full jsfiddle

Thank you!

Upvotes: 0

Views: 33

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You have wrapped the variable selectedMovie in quotes, which makes it as text. simply remove the quotes and every thing will fall in place:

$("#what-movie").html(selectedMovie);

WORKING DEMO

Upvotes: 3

Related Questions