Skip to main content

Ma Functions

Ma function chii?#

Ma functions i code yaunogadzira kana uchida kuzoituma kuti basa kumberi. Nemamwe mashoko, tiri kuti function i basa. Ngatimboti iwewe ukuda kugadzira basa rino mhoresa munhu. Rinogadzirwa se izvi:

Chii chikuitika apa?

Tsananguro

Kubva pana line 1, line 2, na line 3, tagadzira basa rinonzi mhoresaMunhu.

  • Zita re basa rinofana kunyorwa sekunge uri urikugadzira variable.
  • Pamberi pezita re basa panoiswa ma brackets (), muma brackets imomo munogona kuiswa ma variable kana kuti munogona kusaiswa chinhu, sezvaukuona pa code iyi.

Pa line 5:

tangaBasa.mhoresaMunhu()

Apa tiri kutuma computer kuita basa ratagadzira rinonzi mhoresaMunhu().Ma brackets () haasiiwe.

Ita

Mu Application ye ShonaScript

  1. nyora code iyoyi
  2. baya bhatani re round riri pazasi pe screen

Kana kuti

Mu VS Code

Nyora code iyoyi mu index.shona, wochiita izvi:

  1. mu terminal, nyora kuti: node shona.js wobaya enter

  2. mu terminal, nyora kuti: node index.js wobaya enter

Ukaita izvi, unofana kuona mu terminal makanzi

Hesi

Ngatimbobvisa line 5 rakanzi tangaBasa.mhoresaMunhu()

Ita

Mu Application ye ShonaScript

  1. dzima line 5 rekuti tangaBasa.mhoresaMunhu()
  2. baya bhatani re round riri pazasi pe screen

Kana kuti

Mu VS Code

  1. mu index.shona dzima line 5 rekuti tangaBasa.mhoresaMunhu()

  2. mu terminal, nyora kuti: node shona.js wobaya enter

  3. mu terminal, nyora kuti: node index.js wobaya enter

Ukaita izvi, mu terminal hamuna chinonyorwa.

Izvi zvinoitika nekuti wagadzira basa rekumhoresa munhu, asi hauna kuzoudza computer kuti itanga basa racho, saka basa hariitwe kana risina kutangwa na tangaBasa.mhoresaMunhu()

Basa ne ma variable#

Unogona kugadzira basa rinotora variable inozoshandiswa ne basa racho kana razotanga. Ngatomboti iwewe ukuda kugadzira basa rinomhoresa munhu asi ukuda kuzopa basa zita remunhu wekumhoresa. Unoita seizvi:

Chii chikuitika apa?

Tsananguro

Apa ukugadzira basa rinonzi mhoresaMunhu, asi ukuudza computer kuti kana basa iri rave kutangwa, rinofana kupihwa variable inonzi zita ichazoshandiswa na nyora("Hesi ", zita).

Zvekuita

Mu Application ye ShonaScript

  1. nyora code iyoyi
  2. baya bhatani re round riri pazasi pe screen

Kana kuti

Mu VS Code

Nyora code iyoyi mu index.shona, wochiita izvi:

  1. mu terminal, nyora kuti: node shona.js wobaya enter

  2. mu terminal, nyora kuti: node index.js wobaya enter

Ukaita izvi, unofana kuona mu terminal kuti

Hesi Panashe
danger

Ukada kuenda kutanga basa usina kuisa variable, computer ichakuudza kuti

paita problem, basa rinonzi `mhoresaMunhu` ranga richifana kupihwa variable 1 asi iwewe waisa mavariables 0.

Basa re Maths#

Tikuda kugadzira basa rinosanganisa ma nhamba 2 arinenge rapihwa.

Chii chikuitika apa?

tsananguro

Kubva pa line 1 kuzvika pa line 4

Apa tiri kugadzira basa rinonzi sanganisa, basa iri rinofana kuzopihwa ma variable anonzi nhambaYekutanga na nhambaYechipiri anofana kunge ari manhamba nekuti haukwanise kusanganise zvisiri manhamba

Zvekuita

Mu Application ye ShonaScript

  1. nyora code iyoyi
  2. baya bhatani re round riri pazasi pe screen

Kana kuti

Mu VS Code

Nyora code iyoyi mu index.shona, wochiita izvi:

  1. mu terminal, nyora kuti: node shona.js wobaya enter

  2. mu terminal, nyora kuti: node index.js wobaya enter

Ukaita izvi unofana kuona mu terminal makanzi

43

Unogona kuchinja ma nhamba oona kuti chii chinotika, kana kuchinja + oisa -, kana *, kana /

Basa rinoshanda ne nguva#

Mirira _ seconds#

unogona kugadzira basa rinomirira kuzotanga kana papfuura ma seconds aunenge wataura iwewe

Chii chikuitika apa?

Tsananguro

Tangodzokorora kugadzira basa rinonzi mhoresaMunhu sezvataita pakutanga, asi patagadzira basa iri, taudza computer kuti mirira 3 seconds kuitira kuti kana basa iri razotangwa, rinomirira ma seconds enguva 3 robva razotanga.

Ita

Mu Application ye ShonaScript

  1. nyora code iyoyi
  2. baya bhatani re round riri pazasi pe screen

Kana kuti

Mu VS Code

Nyora code iyoyi mu index.shona, wochiita izvi:

  1. mu terminal, nyora kuti: node shona.js wobaya enter

  2. mu terminal, nyora kuti: node index.js wobaya enter

Ukaita izvi, uchaona kuti mu terminal munombotanga musina chinhu kwenguva diki, mozonyorwa kuti

Hesi

Hesi anyorwa padarika 3 seconds dze nguva

Dzokorora _ seconds#

Unogona kugadzira basa rinodzokorora rega kuitika kana papera ma seconds enguva aunenge wataura iwewe sokuti:

Chii chikuitika apa?

Tsananguro

Zvekare tagadzira basa reku mhoresaMunhu, asi apa tikuda kuti basa iri rirambe richidzokororwa kana papfuura 1 second ye nguva.

Ita

Mu Application ye ShonaScript

  1. nyora code iyoyi
  2. baya bhatani re round riri pazasi pe screen

Kana kuti

Mu VS Code

Nyora code iyoyi mu index.shona, wochiita izvi:

  1. mu terminal, nyora kuti: node shona.js wobaya enter

  2. mu terminal, nyora kuti: node index.js wobaya enter

Ukaita izvi, unoona kuti mu terminal mucharamba muchinyorwa Hesi kana papera 1 second yenguva

HesiHesiHesiHesi

Mu terminal imomo munoramba muchinyorwa kuti Hesi kusvika computer yako yadzima

Ndoita sei kana ndichida kuti Hesi amire kunyorwa?
Kuti Hesi amire kunyorwa

Mu Application ye ShonaScript

  1. vhara, ovhura application iyi

Kana kuti

Mu VS Code

  1. mu terminal, baya control na c panguva imwechete. Izvi zvinofana kuita kuti mu terminal mumire kunyorwa kuti Hesi

Gadzira basa rinonyora nguva mu terminal#

ronga
  • basa iri rinofana kunshandisa:

    1. nyora()
    2. Nguva
    3. dzokorora 1 second
  • Kana wapedza tarisa code yacho pasi kana yako yaramba kushandisa

Kushandisa misaBasa.#

Unogona kushandisa misaBasa.mhoresaMunhu() kuita kuti basa rimire. Ngatimboti tikuda kumhoresa munhu ka 3, tobva tamisa basa. Tinoita sei?

ronga

Tichashandisa zvinhu izvi:

  1. basa dzokorora
  2. nyora
  3. kana
  4. enzaniso
  5. misaBasa

Chimboedza kunyora code iyi wega woona kuti zvinoshanda here

Answer

Tsananguro

Tinotarisira kuti waakunzwisisa zvakawanda zviri mucode umu, saka tichangotsanangur zviri kuitika kubva paline 9 kusvika paline 11

  • variable inonzi nhambaYekuverenga icharamba ichiwedzera kubva pana 0 kusvika 3
  • ikasvika pana 3, yaenzana ne variable inonzi nhambaYekumira, saka pa line 10, tikuudza computer kuti misaBasa rinonzi nyoraNguva()