ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Trivia - Trouble getting array of questions to display #167

Closed ArmaniH closed 9 years ago

ArmaniH commented 9 years ago

For the trivia, I'm trying to get a question from my array to appear on screen when the user clicks to begin. The click event is working to display text, but I can't figure out how to get one of the questions to appear instead of just some placeholder text in <p>.

My array

var triviaQuestions = {
  Question1: ['How tall am I?'],
  Question2: ['How old am I?'],

My function
$( ".start" ).click(function() {
      $('p').replaceWith($('id', triviaQuestions[0]));
      $('p').show('slow');
      $('h2').show('slow');
      })

My HTML for

<p style='display: none' class='questions'>This is a trivia question</p>
RobertAKARobin commented 9 years ago

I'm sorry for the delay in responding, Armani! I'm checking it out now.

RobertAKARobin commented 9 years ago

Can you tell me what's going on here:

$('p').replaceWith($('id', triviaQuestions[0]));

A $ should only go around a CSS selector, and 'id', triviaQuestions[0] doesn't look like a selector!

ArmaniH commented 9 years ago

That $ defintiely wasn't helping me out. Removed!

Still not pulling from the array and when I tried to console.log the '.' in console.log is causing an error.

RobertAKARobin commented 9 years ago

Wat. Can you show me the text of the error, and the line that contains the problematic console log?

ArmaniH commented 9 years ago

screen shot 2015-10-26 at 5 24 50 pm

RobertAKARobin commented 9 years ago

That's because you put a csonole.log inside your object, and you can't really do that. You have to put it outside the object. It's similar to how this wouldn't work:

"My name is " + console.log("hello") + "Joe."
ArmaniH commented 9 years ago

That makes perfect sense!

The triviaQuestions array is coming back as undefined

RobertAKARobin commented 9 years ago

Can you copy and paste from where you set triviaQuestions to the console.log?

ArmaniH commented 9 years ago

screen shot 2015-10-26 at 5 38 51 pm

RobertAKARobin commented 9 years ago

You're trying to console.log nothing! Put something in those parentheses. :)