Having Trouble with the Show the Local Weather Challenge

Having Trouble with the Show the Local Weather Challenge
0

#1

I am not sure at this point why the weatherType variable in my CodePen, see below, is not getting displayed. I believe it may have to do with how I am calling the data from the https://fcc-weather-api.glitch.me/ API. Can someone point me in the right direction?

My CodePen link is https://codepen.io/brad10104/pen/PjodOw?editors=1010.

Thanks for all the help in advance.


#2

Hi Brad,

It looks like your $.getJSON function is not getting an array but instead an object.

data.main is an object so it has no reference to data.main[0];


#3

Thanks @Ethanefung, I was able to look up a simple way to convert an object into an array, however I am not sure why it is not working. Could you give it a look for me?

Currently, I am trying to console.log the apiArray, however it does not seem to be going through. Is this an issue with the way that I am using console.log or with the apiArray itself?

Also, am I making this more complicated than it needs to be? I feel like I’m hitting a brick wall.


#4

You need to indent your code to make it easier to see that you have accidentally reversed the order of your missing a closing parentheses and closing curly brackets on your $(document).ready callback function. Once you indent your code and fix the order of the parentheses/brackets, then you will see the console.log(apiArray); is in the wrong place to get any data and the last line of:

})

is not needed at all.

You will also be able to look at your browser’s console (Ctrl+Shft+J in Chrome) to see a specific error related a variable you are trying to use called obj


#5

Hi @brad10104,
Don’t worry dude we’ve all been there. As a matter of fact I’m working on a project now where I feel the same. But I think you’re more than capable to do this. You got this, and you have my support.

I will have to agree with randell and say that it is very important to have clean syntax when it comes to coding. What you’ll find is that the more structure you implement in your code, the easier it is to reason about it. If your spacing is not consistent, then it’s easier to miss things.

Do this:

function foo() {

  const variable1 = 'Clean';
  const variable2 = 'Looking';  
  const variable3 = 'Syntax';

  return bar();
}

function bar() {
  return 'is easy to reason about, and catch syntax errors';
}

Not this:

const aDirty_Example = function() {

    const λ = foo();
function foo() { return x+ ' ' + sign }

             let sign = () => 'might work, ';
    


let example = 'but'
  var x = 'this'
return [].concat(λ, example, 'is much harder to reason about').join('')
}

Make things easy for yourself. With that said I’d also look at the expected arguments that the $.getJSON function is looking for, and in what order those arguments must be supplied to the function.

http://api.jquery.com/jquery.getjson/