Autor | Zpráva | ||
---|---|---|---|
robbie Profil * |
#1 · Zasláno: 13. 1. 2016, 14:50:46
Zdravím, chtěl jsem poprosit o radu, nechápu, proč mi nefunguje v prohlížeči tento kod:
Dekuji za pomoc. R. <!doctype html> <html> <head> <title>Chapter 8 Exercise 4</title> <script type="text/javascript"> function Star(constell,type,specclass,magnitude) { this.constellation = constell; this.type = type; this.spectralClass = specclass; this.mag = magnitude; } star["Polaris"] = new Star("Ursa Minor","Double/Cepheid","F7",2.0); star["Mizar"] = new Star("Ursa Major","Spectroscopic Binary","A1 V",2.3); star["Aldebaran"] = new Star("Taurus","Irregular Variable","K5 III",0.85); star["Rigel"] = new Star("Orion","Supergiant with Companion","B8 Ia",0.12); star["Castor"] = new Star("Gemini","Multiple/Spectroscopic","A1 V",1.58); star["Albireo"] = new Star("Cygnus","Double","K3 II",3.1); star["Acrux"] = new Star("Crux","Double","B1 IV",0.8); star["Gemma"] = new Star("Corona Borealis","Eclipsing Binary","A0 V",2.23); star["Procyon"] = new Star("Canis Minor","Double","F5 IV",0.38); star["Sirius"] = new Star("Canis Major","Double","A1 V",-1.46); star["Rigil Kentaurus"] = new Star("Centaurus","Double","G2 V",-0.01); star["Deneb"] = new Star("Cygnus","Supergiant","A2 Ia",1.25); star["Vega"] = new Star("Lyra","White Dwarf","A0 V",0.03); star["Altair"] = new Star("Aquila","White Dwarf","A7 V",0.77); if ("Polaris" in star) { star["Polaris"].aka = "The North Star"; alert("Polaris found and is also known as " + star["Polaris"].aka); } for (var element in star) { if ("aka" in star[element]) { alert(element + " is in " + star[element].constellation); } } </script> <body> </body> </html> |
||
Chamurappi Profil |
#2 · Zasláno: 13. 1. 2016, 15:01:03
Reaguji na robbieho:
Proměnná star neexistuje, takže do star["Polaris"] těžko můžeš něco přiřadit.
Chyba se vůbec netýká operátoru in . Nebo jsi neuvedl kompletní kód.
|
||
robbie Profil * |
#3 · Zasláno: 13. 1. 2016, 15:27:52
Chamurappi:
Dekuju moc, čerpám z jedné anglické knihy-učebnice a tam to nemeli, tak me zajimalo, kde je problém. Jeste jednou dekuju. R. |
||
KryVosa Profil |
#4 · Zasláno: 13. 1. 2016, 20:27:42
Vyřešit jde jednoduše, na začátek scriptu přidáš
var star=[]; .
|
||
Radek9 Profil |
#5 · Zasláno: 13. 1. 2016, 21:08:02
KryVosa:
Proč pole? |
||
Časová prodleva: 9 let
|
0