Good night!
When parsing a seemingly lightweight script, I found an not quite clear moment for myself.
Javascript
:
var planetList = new Array(); planetList[0] = 'ΠΠ΅ΡΠΊΡΡΠΈΠΉ'; planetList[1] = 'ΠΠ΅Π½Π΅ΡΠ°'; planetList[2] = 'ΠΠ΅ΠΌΠ»Ρ'; planetList[3] = 'ΠΠ°ΡΡ'; var wayToSun = new Array(); wayToSun[0] = '52 ΠΌΠ»Π½.ΠΊΠΌ'; wayToSun[1] = '108 ΠΌΠ»Π½.ΠΊΠΌ'; wayToSun[2] = '149 ΠΌΠ»Π½.ΠΊΠΌ'; wayToSun[3] = '228 ΠΌΠ»Π½.ΠΊΠΌ'; var planetDiameter = new Array(); planetDiameter[0] = '4 880 ΠΊΠΌ'; planetDiameter[1] = '12 100 ΠΊΠΌ'; planetDiameter[2] = '12 750 ΠΊΠΌ'; planetDiameter[3] = '6 800 ΠΊΠΌ'; function doCount(){ var userText = document.getElementById('planetName').value; for( var i = 0; i < planetList.length; i++) { if(planetList[i] == userText){ break; } } document.write('<p class="hightlight">'+planetList[i]+'</p>'); document.write('<p class="hightlight">Π Π°ΡΡΡΠΎΡΠ½ΠΈΠ΅ Π΄ΠΎ ΡΠΎΠ»Π½ΡΠ°: '+wayToSun[i]+'</p>'); document.write('<p class="hightlight">ΠΠΈΠ°ΠΌΠ΅ΡΡ ΠΏΠ»Π°Π½Π΅ΡΡ: '+planetDiameter[i]+'</p>'); }
HTML
:
<label for="planetName">ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΏΠ»Π°Π½Π΅ΡΡ:</label> <input type="text" id="planetName" name="planetName" /> <input type="button" id="counter" value="Π Π°ΡΡΡΠΈΡΠ°ΡΡ" onclick="doCount()"/>
As I said everything to the banality is simple, mat.part so say. But the situation why the script stops βworkingβ when the userText
variable userText
declared outside the function body (if I understand correctly, in this case it is global), I canβt master it.
window
object: window.userText = document.getElementById ('planetName'). Value; var foo = window.userText; - neoasceticnull
. this is an incomprehensible moment. according to my idea, it should be global and be accessible function. - LeD4eGnull
or stillundefined
? Create a jsfiddle , we'll see. - neoascetic