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

Spider-man

Firstly, I should make my biases clear, but I'm pretty sure it's obvious. I've seen the Sam Raimi trilogy and of course, I will be comparing it to the reboot. After all, the reboot came a little bit too soon after the trilogy. Most of what follows will probably just be my personal preferences and gripes. Warning, spoilers abound. 1. Peter Parker I liked the doe-eyed Tobey Maguire more as the day-to-day Peter Parker. He's the nerdy, unsure of himself, normal guy. Andrew Garfield's cheeky boyish look doesn't make me buy the Peter Parker-ness. Andrew Garfield looks like he belongs to some teen series. 2. Mary Jane versus Gwen Stacy I hated Kirsten Dunst's Mary Jane. She's completely helpless like the traditional damsel in distress and sometimes her whining about her relationship with Peter Parker, seems, idk, petty, and sometimes she seems to not understand his predicament of being Spider-man and not being able to be there for her all th

Memori Keropok Lekor

Setiap kali ada school trip ke SBP pantai timur di Pahang atau Terengganu (seingatnya, pernah mengunjungi SESTER-Perfect Score Zon Timur 2009, SBPI B. Rakit-HKSBP Zon timur 2008 kot? SHAH Pekan- HKSBP Zon Timur 2006, SESMA-bermalam untuk Sambutan Hari Guru Kebangsaan. Eh, who knows where the headgirl of SESMA 2009 is right now? and....tu setakat yang ingatlah tentang sekolah yang dikunjungi), kalau berkesempatan lalu Batu Buruk, mesti singgah beli keropok lekor. Best gila. Sekali beli mesti habis dalam RM 50, sebab beli untuk cikgu, untuk kelas, untuk ahli dorm. Sesampainya di kelas, keropok lekor akan dibahagikan untuk bahagian budak-budak (budak-budak?) laki and budak-budak perempuan. Di bahagian depan kelas, budak-budak laki dalam sekelip mata sahaja menghabiskan keropok. Budak-budak perempuan pula makan di meja belakang (selalunya meja akulah tu. Nampak sangat muka kuat "jjella", huhu). Kita makan 'cover-cover', konon ayulah kot. And then, berduyun-duyun pergi

My Blog Looks So GAYY Now

I love blogger's new toy: the template designer thannggg.. love the jelly beans!   I changed my blog name to Gambar Gajah (ARAHAN: sila teliti gambar rajah gajah di bawah dan jawab soalan-soalan berikutnya ) , just a random thought, and it's a funny name, but don't expect me to post pictures of elephants .   okay, just to commemorate the change of name, nah ..here's one snagged from the internet..     Gambar Rajah Gajah 1.1  Berapa kali blog ini sudah bertukar nama? _________________________________ (5 m) 2. Berapakah umur blog ini? __________________________________(5 m) Jumlah: __ / 10 m hahahaha, lawak..lawak..macam tak ada kerja je aku ni Alhamdulillah, Allah Maha Kuasa Keputusan Rayuan JPA PILN: Engineering, Canada International Canadian Pre-University (ICPU) 1 Tahun at Taylor's College, Subang Jaya