Var result function converttogrademark variable eg

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;script type="text/javascript"> Actually happens very often var result; When to use local / global variables? var result; function convertToGrade(mark) variable eg. previous "Counter" Use global { example We should use global variables if (mark>80) result='A'; ONLY WHEN really necessary and else if (mark>65) appropriate. result='B'; else if (mark>45) Use local variable(Preferred!!) we often use result='C'; variable only within the function and no else result='F'; need to keep it after the function stops. * return result; } * "return result;" actually means } if (m a rk>8 0 ) re s ult='A'; e ls e if (m a rk>6 5 ) re s ult='B'; e ls e if (m a rk>4 5 ) re s ult='C '; e ls e re s ult='F'; re turn re s ult; a func tio n c o nve rtT o P a s s Fa il(m a rk) { var result; if (m a rk>4 5 ) re s ult='P a s s '; e ls e re s ult='Fa il'; } re turn re s ult; (CS1301) Introduction to Computer Programming City Univ of HK / Dept of CS / Helena Wong...
View Full Document

This note was uploaded on 03/10/2012 for the course CS 1301 taught by Professor Dr.wong during the Winter '08 term at City University of Hong Kong.

Ask a homework question - tutors are online