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 urikugadziravariable
. - Pamberi pezita re
basa
panoiswa ma brackets()
, muma brackets imomo munogona kuiswa mavariable
kana kuti munogona kusaiswa chinhu, sezvaukuona pacode
iyi.
Pa line 5
:
tangaBasa.mhoresaMunhu()
Apa tiri kutuma computer kuita basa
ratagadzira rinonzi mhoresaMunhu()
.Ma brackets ()
haasiiwe.
Ita
Mu Application ye ShonaScript
- nyora
code
iyoyi - baya bhatani re round riri pazasi pe screen
Kana kuti
Mu VS Code
Nyora code
iyoyi mu index.shona
, wochiita izvi:
mu
terminal
, nyora kuti:node shona.js
wobayaenter
mu
terminal
, nyora kuti:node index.js
wobayaenter
Ukaita izvi, unofana kuona mu terminal
makanzi
Hesi
Ngatimbobvisa line 5
rakanzi tangaBasa.mhoresaMunhu()
Ita
Mu Application ye ShonaScript
- dzima
line 5
rekutitangaBasa.mhoresaMunhu()
- baya bhatani re round riri pazasi pe screen
Kana kuti
Mu VS Code
mu
index.shona
dzimaline 5
rekutitangaBasa.mhoresaMunhu()
mu
terminal
, nyora kuti:node shona.js
wobayaenter
mu
terminal
, nyora kuti:node index.js
wobayaenter
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
- nyora
code
iyoyi - baya bhatani re round riri pazasi pe screen
Kana kuti
Mu VS Code
Nyora code
iyoyi mu index.shona
, wochiita izvi:
mu
terminal
, nyora kuti:node shona.js
wobayaenter
mu
terminal
, nyora kuti:node index.js
wobayaenter
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 MathsTikuda 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
- nyora
code
iyoyi - baya bhatani re round riri pazasi pe screen
Kana kuti
Mu VS Code
Nyora code
iyoyi mu index.shona
, wochiita izvi:
mu
terminal
, nyora kuti:node shona.js
wobayaenter
mu
terminal
, nyora kuti:node index.js
wobayaenter
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 _ secondsunogona 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
- nyora
code
iyoyi - baya bhatani re round riri pazasi pe screen
Kana kuti
Mu VS Code
Nyora code
iyoyi mu index.shona
, wochiita izvi:
mu
terminal
, nyora kuti:node shona.js
wobayaenter
mu
terminal
, nyora kuti:node index.js
wobayaenter
Ukaita izvi, uchaona kuti mu terminal
munombotanga musina chinhu kwenguva diki, mozonyorwa kuti
Hesi
Hesi
anyorwa padarika 3 seconds dze nguva
#
Dzokorora _ secondsUnogona 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
- nyora
code
iyoyi - baya bhatani re round riri pazasi pe screen
Kana kuti
Mu VS Code
Nyora code
iyoyi mu index.shona
, wochiita izvi:
mu
terminal
, nyora kuti:node shona.js
wobayaenter
mu
terminal
, nyora kuti:node index.js
wobayaenter
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
Kuti Hesi
amire kunyorwa
Mu Application ye ShonaScript
- vhara, ovhura application iyi
Kana kuti
Mu VS Code
- mu
terminal
, bayacontrol
nac
panguva imwechete. Izvi zvinofana kuita kuti muterminal
mumire kunyorwa kutiHesi
terminal
#
Gadzira basa rinonyora nguva mu ronga
basa iri rinofana kunshandisa:
nyora()
Nguva
dzokorora 1 second
Kana wapedza tarisa
code
yacho pasi kana yako yaramba kushandisa
misaBasa.
#
Kushandisa Unogona kushandisa misaBasa.mhoresaMunhu()
kuita kuti basa rimire. Ngatimboti tikuda kumhoresa munhu ka 3
, tobva tamisa basa
. Tinoita sei?
ronga
Tichashandisa zvinhu izvi:
basa dzokorora
nyora
kana
enzaniso
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
inonzinhambaYekuverenga
icharamba ichiwedzera kubva pana 0 kusvika 3- ikasvika pana 3, yaenzana ne
variable
inonzinhambaYekumira
, saka paline 10
, tikuudzacomputer
kutimisaBasa
rinonzinyoraNguva()