Toinen viikkotehtävä on nyt julkaistu. Taas on gitlabissa tarjolla valmis pohja, josta voitte forkata itsellenne oman repon. Tämän tehtävän taustalla pyörii palvelimella jonkin verran viritelmiä, jotka ovat ensimmäistä kertaa käytössä. Ilmoitelkaa, jos löydätte vikoja.
https://appro.mit.jyu.fi/tiea2120/vt/vt2/
Myös ensimmäinen vertaisarviointi on tulossa aivan pian.
On Wed, 27 Sep 2023, Tommi Lahtonen via Tiea2120 wrote:
Tähän tehtävään liittyen löytyy myös vähän taustoitusta asynkronisiin funktioihin täältä:
https://appro.mit.jyu.fi/tiea2120/luennot/async/
Itse ei tarvitse asynkronisia funktioita rakentaa, kuin ehkä viikkotehtävän vitostasolla.
Huomioikaa kuitenkin jo heti ykköstasolla, että omaa koodia ei voi kirjoittaa ihan mihin sattuu, vaan se on kirjoitettava sinne mihin valmiissa pohjassa sitä ehdotetaan.
WWW-sivun latautumisessa ja javascript-koodinne suorituksessa on vaiheita, jotka on huomioitava. Esim. ette voi javascript-sovelluksella käsitellä www-sivun sisältöä ennen kuin se on latautunut. Valmiissa pohjassa javascript-koodit ladataan heti sivun head-osassa eli ennen kuin sivun loppuosa on valmis. Esim. jos kirjoitatte valmiin lomakkeen sivulle, ette voi käsitellä sitä ennen kuin se on latautunut. Tätä varten on olemassa load-tapahtuma, joka suoritetaan vasta www-sivun kokonaan latauduttua. Valmiissa viikkotehtäväpohjassa tämä huomioidaan eli vasta sivun latauduttua alkaa varsinainen sovelluskoodi. Tehtävässä tarvitaan www-palvelimelta erikseen ladattavaa dataa, joka ladataan valmiissa pohjassa vasta load-tapahtuman yhteydessä. Tämän lataamisen valmistuminen pitää myös erikseen odottaa ennen kuin dataa voi käsitellä.
On Wed, 27 Sep 2023, Tommi Lahtonen via Tiea2120 wrote:
Toinen viikkotehtävä on nyt julkaistu. Taas on gitlabissa tarjolla valmis pohja, josta voitte forkata itsellenne oman repon. Tämän tehtävän taustalla pyörii palvelimella jonkin verran viritelmiä, jotka ovat ensimmäistä kertaa käytössä. Ilmoitelkaa, jos löydätte vikoja.
Toisen viikkotehtävän datassa oli pieni bugi. Kannattaa käydä resetoimassa oman sovelluksenne data eli avata osoite:
https://appro.mit.jyu.fi/cgi-bin/tiea2120/vt2.cgi/clear
Joukkueiden leimaustapojen esitystavassa oli vikaa eli rakenteessa seikkaili yksi orpo leimaustapa-elementti. Viikkotehtävän aiheeseen sopivasti liittyen kyseessä oli meikäläisen DOM-koodissa ollut bugi.
Viikkotehtävän xmldata ajetaan läpi sovelluksesta, joka hieman sekoittaa dataa eli mm. muuttelee datassa olevia tunnisteita hardkoodauksen estämiseksi. Sovellus myös järjestelee datan elementtejä satunnaiseen järjestykseen, koska en halua, että koodaatte liikaa luottaen elementtien tai attribuuttien järjestykseen vaan teette jonkun varmemman ratkaisun. Tässä elementtien järjestämisessä oli parametreina elementtien nimiä ja siellä luki "leimaustapa", kun piti lukea "leimaustavat". Kun tuolla nyt sattuu olemaan sekä leimaustavat- että leimaustapa-elementtejä niin sittenhän tuo sotki yksittäisen leimaustapa-elementin ihan väärään paikkaan.
Tässä vielä kyseinen koodi, joka on pythonia, mutta ei javascriptina juurikaan eroaisi tästä. DOM-rajapinta on siis standardi eli kaikissa kielissä on käytössä samat metodit. Virheellinen koodi oli:
elementit = ["jasenet", "leimaustapa", "nimi"]
Tämän piti olla:
elementit = ["jasenet", "leimaustavat", "nimi"]
ja jatkossa elementit käytiin näin läpi: shuffle(elementit) # sekoitetaan listan järjestys for e in elementit: # lisätään kukin elementti uudelleen joukkueen lapseksi, mutta # järjestys on nyt satunnainen joukkue.appendChild( joukkue.getElementsByTagName(e)[0] )
Virheellinen koodi otti siis ensimmäisen leimaustapa-elementin ja lykkäsi sen suoraan joukkue-elementin lapseksi, vaikka piti käsitellä leimaustavat-elementtiä.