flash - Function returning -
why program output text "future" function year()?
in case, b+c equaling 56, var year should fall under (b+c) > 0 && (b+c) < 1000) , return "roman", instead returns "future"...
i got work if add this:
var period:string = (year(b,c));
and in body function, make conditionals check period. example
if (period == "future")
but don't understand why need this. returning string, why have set variable? there no compiler errors not syntactical?
var a:string = "tim"; var b:int = 50; //change int want var c:int = 6; //change int want var d:string = "kyle"; var sum:int = b+c; function friend(d:string, a:string):string { return d+" , "+a; } function year(b:int, c:int):string { if( (b+c) > 2000 ) return "future"; else if( (b+c)> 1000 && b+c< 2000) return "colonial"; else if( (b+c) > 0 && (b+c) < 1000) return "roman"; else if( (b+c) < 0) return "medieval"; else return "fail"; } function intro(sum, friend):string { return "once upon time, in year "+ b+c +", "+friend; } function body(year):string { if ("future") return " saw flying saucer , descided wanted alien."; else if ("colonial") return " got off the mayflower , descided wanted eat turkey."; else if ("roman") return " taking break after fierce battle romans."; else if ("medieval") return " saved princess in shining armor after slaying dragon."; else if ("fail") return " got f on exam."; else return " got f on test."; } trace (b+c); trace(intro(sum, friend(d, a)) + body(year));
you passing functions parameters other functions. need pass result of function call parameters other functions.
also, if use int+int in string concatination, need put calculation between brackets. use (int+int) instead.
in intro function, passed in sum parameter, did not use it. instead recalculated b+c.
try this:
var a:string = "tim"; var b:int = 50; //change int want var c:int = 6; //change int want var d:string = "kyle"; var sum:int = b+c; function friend(d:string, a:string):string { return d+" , "+a; } function year(b:int, c:int):string { if( (b+c) > 2000 ) return "future"; else if( (b+c)> 1000 && b+c< 2000) return "colonial"; else if( (b+c) > 0 && (b+c) < 1000) return "roman"; else if( (b+c) < 0) return "medieval"; else return "fail"; } function intro(sum:int, friend:string):string { return "once upon time, in year "+ sum +", "+friend; } function body(year:string):string { if ("future") return " saw flying saucer , descided wanted alien."; else if ("colonial") return " got off the mayflower , descided wanted eat turkey."; else if ("roman") return " taking break after fierce battle romans."; else if ("medieval") return " saved princess in shining armor after slaying dragon."; else if ("fail") return " got f on exam."; else return " got f on test."; } trace (b+c); trace(intro(sum, friend(d, a)) + body(year(b, c)));
Comments
Post a Comment