Copy link to clipboard
Copied
Its an assignment that I've spent hours on:
http://imageshack.us/a/img834/7124/273e.png
http://imageshack.us/a/img706/4691/fhfd.png
That's how far I've gotten so far, next up is my code:
__________________________________________________________________________________________________________________________
var body_txt:TextField = new TextField();
body_txt.x = 225;
body_txt.y = 300;
body_txt.autoSize = TextFieldAutoSize.LEFT;
var myFormat:TextFormat= new TextFormat();
var yourPurchase:String;
var yourDiscount:String;
var yourPrice:String;
var discount:Number;
var total:Number;
yourPurchase = max_txt.text;
discount: 10.00 / 10%
yourDiscount = discount_txt.text;
yourPrice = price_txt.text;
total = yourPurchase - discount
if(yourDiscount)
{
trace();
}
else
{
trace();
}
__________________________________________________________________________________________________________________________
As you can see, I have no clue on how to get the discount written in code, I don't know how.
Please explain as best as you can about how to solve this dilemma (in Laymen's Terms if possible). Thank you!
use:
...
______________________________________________________________________ ____________________________________________________
var body_txt:TextField = new TextField();
body_txt.x = 225;
body_txt.y = 300;
body_txt.autoSize = TextFieldAutoSize.LEFT;
var myFormat:TextFormat= new TextFormat();
// i'm not sure what the above is
var yourPurchase:Number;
var yourDiscount:Number;
var discount:Number=.1;
// the code below (up to formatF) needs to execute AFTER the user completes entry into max_txt
yourPurchase =
Copy link to clipboard
Copied
use:
______________________________________________________________________ ____________________________________________________
var body_txt:TextField = new TextField();
body_txt.x = 225;
body_txt.y = 300;
body_txt.autoSize = TextFieldAutoSize.LEFT;
var myFormat:TextFormat= new TextFormat();
// i'm not sure what the above is
var yourPurchase:Number;
var yourDiscount:Number;
var discount:Number=.1;
// the code below (up to formatF) needs to execute AFTER the user completes entry into max_txt
yourPurchase = Number(max_txt.text);
if(yourPurchase>10){
yourDiscount=discount*yourPurchase;
} else {
yourDiscount=0;
}discount_txt.text=formatF(yourDiscount);
price_txt.text = formatF(yourPurchase*(1-discount));
function formatF(n:Number):String{
// now write a function that converts numbers to dollars and cents for display
}
Copy link to clipboard
Copied
// now write a function that converts numbers to dollars and cents for display
Thank you greatly for the help, I appreciate it and am almost finished this assignment. One last question: I tried to convert numbers to dollars but I am not sure how. I am still a beginner with programming, but I am slowly getting better. May I ask you how I should convert it? I've looked on Google for help.
Copy link to clipboard
Copied
:
function formatF(n:Number):String{
var s:String = String(Math.round(100*n)/100);
if(s.indexOf(".")==-1){
return "$"+s+".00";
} else {
while(s.indexOf(".")>=s.length-2){
s=s+"0";
}
}
return "$"+s
}
Copy link to clipboard
Copied
Is it ethical to just hand someone the code for a homework assignment?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now