/    Sign up×
Community /Pin to ProfileBookmark

Need Help With HomeWork

having a real hard time with this script here is all the info it is due the 19th and would be a really big help thanks

Prompt the user to enter the number of items purchased and the cost of the item. Remember to parse
each of the inputs as you will use them in calculations.
You have 2 different options for shipping, either a flat rate of 10% of total cost or a shipping schedule.
You have to determine the total price of the item using each shipping method and output which shipping
method is cheaper.
First, calculate the subtotal of the transaction by multiplying the amount of items purchased by the cost
of the item. Store this value into a variable called subtotal.
Second, calculate the cost of the flat rate shipping option and store the result in a variable called total1.
Calculation should look like this…
total1 = subtotal + (subtotal * .1);
Next, calculate the cost of shipping using the second method. Use the following shipping schedule.
Subtotal Shipping Cost
Under 25 dollars $4.56
Over 25 dollars $7.39
To do this, use an if statement to determine the amount of shipping to add onto the item. If the subtotal
is under $25, add $4.56 onto the subtotal and store the result in a variable called total2. If the subtotal is
over $25, add $7.39 onto the subtotal and store the result into total2.
Your if statement should look like this…
if( subtotal > 25 )
{
total2 = subtotal + 7.39;
}
else
{
total2 = subtotal + 4.56;
}
Print the cost per item, the number of items purchased, the subtotal, total1, and total2 all on separate
lines.
Page 2 of 2
Last, determine which was the cheaper shipping method and print a suitable message. Compare total1
and total2 using
if( total1 < total2 )
{
print a message stating flat rate shipping method is cheapest.
}
else
{
print a message stating shipping schedule is cheapest.
}
Sample Output
Cost of item: 5.50
Number of items: 6
Subtotal: 33
Flat rate shipping total: 36.30
Shipping schedule total: 40.39
Flat rate shipping is cheaper!!!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KorDec 13.2007 — and? What have you done so far? We don't do somebody else's homework, we only [I]help[/I] the others to correct their work, if something went wrong...
Copy linkTweet thisAlerts:
@pinpopauthorDec 13.2007 — and? What have you done so far? We don't do somebody else's homework, we only [I]help[/I] the others to correct their work, if something went wrong...[/QUOTE]

ok i will show what i did
Copy linkTweet thisAlerts:
@pinpopauthorDec 13.2007 — this is what i did i won't show up in the browser

<html>

<head>

<title>

</title>

</head>

</body>

<script language="javascript">

var numberitem = parseInt(prompt("Enter Number Of Items "));

var cost= parseInt(prompt("Enter Cost of Items "));

var subtotal = (numberitem * cost);

total1 = subtotal + (subtotal *
.1);

document.write(" Cost Of Item "cost);

document.write(" Number of Items "numberitem");

document.write(" Subtotal "subtotal"

if( subtotal > 25 )

{

total2 = subtotal + 7.39;

}

else

{

total2 = subtotal + 4.56;

}



</script>

</body>

</html>
Copy linkTweet thisAlerts:
@pinpopauthorDec 14.2007 — will give 25 dollars in paypal for help please!!
Copy linkTweet thisAlerts:
@pinpopauthorDec 14.2007 — look what i did ?

<html>

<head>

<title>

</title>

</head>

</body>

<script language="javascript">

var cost = parseInt(prompt("Enter Cost of Items "));

var item = parseInt(prompt("Enter Number Of Items "));

var subtotal = cost * item;

var total1 = subtotal + (subtotal *
.1);

var total2 = subtotal + 7.39

document.write("Cost of Item : " + cost);

document.write("<br> Number Of Items : " + item);

document.write("<br> Subtotal : " + subtotal);

document.write("<br> Flat Rate Shipping Total : " + total1);

document.write("<br> Shipping Schedule Total : " + total2);

if(total1 > total2)

{

document.write("<br> Shipping Schedule is Cheaper!!!");

}

</script>

</body>

</html>

Which equals

Cost of Item : 500

Number Of Items : 20

Subtotal : 10000

Flat Rate Shipping Total : 11000

Shipping Schedule Total : 10007.39

Shipping Schedule is Cheaper!!!
Copy linkTweet thisAlerts:
@nap0leonDec 15.2007 — A couple of minor issues...

1- IE7 (and presumably other browsers) don't like "scripted windows". Even though I say "Temporarily allow scripted windows" when the page loads, it won't run them unless I turn off all pop-up blockers for the site hosting the page). Perhaps this is not an issue for your exercise.

2- You left out the part where shipping cost is only $4.56 if total is < $25.

To fix the first issue, change your "prompts" to use form fields and add a link for "Calculate" that reads the form fields...

e.g.,
[CODE]
<form name="form1">
Enter Cost of Items: <input type="text" id="CostOfItems"/>
<br/><a href="javascript:CalculateShipping();">Calculate Shipping</a>
</form>
<script>
function CalculateShipping() {
var cost = parseInt(document.form1.CostOfItems.value);
...
}
</script>
[/CODE]
×

Success!

Help @pinpop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...