Skip to main content

CS Flex 3 Test Revision

Task One:

1. You have two buttons. One labeled "Timestable" and the other "Divison table". The Timestable button calls the timesTable function, and the Division table button calls the divisionTable function.
2. Assume that the logIT function has already been given, write the codes for the timesTable and divisionTable functions so that as the button is clicked, the respective tables will be printed out in the debug logger.

Answer:

private function timesTable ():void{
for (var i:int=0; i<13; i++){
for (var j:int=0; j<13; j++){
logIT (String(i) + ' times ' + String(j) + ' = ' + String (i*j));
}
}
}

private function divisionTable ():void{
for (var i:int=0; i<13; i++){
for (var j:int=0; j<13; j++){
logIT (String(i*j) + ' divided by ' + String(i) + ' = ' + String (j));
}
}
}

 
 
Task Two:
 
1. You are given a text input box and a button. On click of the button, whatever information from the text input box will be in reversed order and displayed in Alert.show.
2. Write the codes for that function.
 
Answer:
 
Create a variable to extract information from the text input box, and another variable to be displayed on the Alert.show.
 
private function reverseText ():void{
var reverseText:String = txiInput.text;
var inAlert:String = ' ';
for (var i:int= reverseText.length-1; i<-1; i--){
inAlert = inAlert + reverseText.charAt(i);
}
 Alert.show(inAlert);
}
 
 
 
Task Three:
 
1. You are given a text input box and a button.
2. Create a function whereby on click, the total of vowels in whatever information from the text input box is displayed in Alert.show. Change upper case characters to lower case when extracting information from the text input box.
 
 
Answer:
 
Similar to the previous problem, a variable must be created to extract information from the text input box, as well as to display or count the number of vowels.
 
You can use: a switch statement, five if statements or one if statement.
 
using switch:
 
private function vowelCount():void{
var sampleText:String txiInput.text.toLowercase();
var vowelTotal:int = 0;
for (var i:int=0; i
switch (sampleText.charAt(i)){
case 'a': vowelTotal++;
             break;
case 'e': vowelTotal++;
             break;
case 'i': voweTotal++;
             break;
case 'o': vowelTotal++;
             break;
case 'u': vowelTotal++;
             break;
default:  break;
}
}
Alert.show ('Total vowel is ' + String(vowelTotal));
}
 
 
erh, I'll figure out the if statement sometime.

Comments

Nana said…
for task three, actually the for loop code is:

for(var i:int=0; i<sampleText.length; i++)

I don't know why blogger doesn't like it, so I've not been able to display it.

Popular posts from this blog

Of Engineering and Life

Betrayed by the worst atrociously shameful mark of femininity, the shy, embarrassed, immature, self-conscious, awkward, school girl blush in the presence of a drop dead attractive member of the opposite sex. *facepalm* I'm gonna be fricking 21 years old, hormones, please stabilize.


Taming Tigers

If you have not read this book, get you hands on it quick!
Yes, I'm serious, it is that good.

why?
simply because it is unforgivingly, brutally honest.
What I love of this book is basically the fact that not a single word has gone to waste. Every single description is relevant, and makes for a pinpoint analogy of each scenario in the book. When you traverse each sentence, you already have an idea what the author is trying to portray in the way he describes what the characters do, wear, walk, talk. the simple gestures represent the very soul of the culture so imminently depicted in this book.
And the main character, Balram, seems so real that you could almost believe that he actually runs around in the streets, er, slums of India. The complexity of emotions and the inner turmoil he felt as he expresses his views on the issues.
The author's ideas of a new-age caste of small-bellied and big-bellied people and the Rooster Coop has been compellingly displayed along the storyline, and y…

Kiddies

Okay, yesterday, I went to my little sister's kindergarten sports day held at SMK Seksyen 5, Wangsa Maju Hall. Well, the field is wet because it has been raining almost every day in KL, well, in my area.
Anyway, I was the photographer that day, a tak bertauliah one, mind you. Here are some of the pics. They are so cute!

bacaan ikar

This is not a running in a sack event, this is a running sack

balloon haul
bean bag race






future Rahman formation?Well, I guess that's about that.