Læringsmål:
- Funksjoner, switch og for-løkker
Pensum
- Kap PLACEHOLDER
a) Skriv funksjonen daysInMonth ved hjelp av en switch-setning. Den skal ta inn et månedsnummer: 1 = Januar, 2 = Februar osv. Funksjonen skal returnere antall dager i måneden. Bidrag fra skuddår neglisjeres. Hvis argumentet er ugyldig skal det returneres 0. Feks gir måned "appelsin" ingen mening og vi ønsker å beskytte oss mot slikt.
daysInMonth ("Appelsin") % skal skrive ut 0
daysInMonth (1) % skal skrive ut 31
daysInMonth (2) % skal skrive ut 28
daysInMonth (3) % skal skrive ut 31
daysInMonth (4) % skal skrive ut 30
daysInMonth (5) % skal skrive ut 31
daysInMonth (6) % skal skrive ut 30
daysInMonth (7) % skal skrive ut 31
daysInMonth (8) % skal skrive ut 31
daysInMonth (9) % skal skrive ut 30
daysInMonth (10) % skal skrive ut 31
daysInMonth (11) % skal skrive ut 30
daysInMonth (12) % skal skrive ut 31
daysInMonth (13) % skal skrive ut 0
daysInMonth (pi) % skal skrive ut 0