2016-10-03 24 views
-3

私は完璧に動作する天気予報アプリを構築しました。私は割り当てられたAPIからweather id変数で変更されるアイコンを追加することに決めました。これは、if文の最初のIDのために働くが、ここの部分は私のコードであれば、それ内のステートメントは、他のために動作しない場合、私は他に追加するとき:なぜこの「if文」が機能しないのですか?

 //weather icons check  
      if(weatherId=800){ 
      $('#type').css('background-image', 'url(http://publicdomainvectors.org/photos/weather-clear.png)'); 
      } 
      else if(weatherId>=801 && weatherId<=804){ 
       $('#type').css('background-image','url(http://publicdomainvectors.org/tn_img/stylized_basic_cloud.png)'); 
      } 
      else if(weatherId>=300 && weatherId<=531){ 
       $('#type').css('background-image','url(http://publicdomainvectors.org/tn_img/sivvus_weather_symbols_4.png)'); 
      } 

私はこの文で何かをしないのです?? ?

+3

'weatherid = 800'は割り当てです。それを 'if(weatherId == 800){' –

+0

'weatherId = 800' – epascarello

+1

' weatherid === 800'トリプル・イコールにするのが最良です。 –

答えて

3

あなたは「場合は、あなたの最初に1つの等しい記号(=)を逃しまし。それはそうでなければなりません:

if(weatherId==800){ 
    $('#type').css('background-image', 'url(http://publicdomainvectors.org/photos/weather-clear.png)'); 
} 
else if(weatherId>=801 && weatherId<=804){ 
    $('#type').css('background-image','url(http://publicdomainvectors.org/tn_img/stylized_basic_cloud.png)'); 
} 
else if(weatherId>=300 && weatherId<=531){ 
    $('#type').css('background-image','url(http://publicdomainvectors.org/tn_img/sivvus_weather_symbols_4.png)'); 
} 
+0

私はそれを実現しました。ありがとうございました – MikeL5799

+0

@ MikeL5799あなたがこの問題を解決した場合、あなたは答えを受け入れることができます:) –

2

変更

if(weatherId=800){ 

if(weatherId==800){ 

へのお知らせダブル==

+0

それは、あまりにもありがとう – MikeL5799

関連する問題