/    Sign up×
Community /Pin to ProfileBookmark

Javascript Help

Need help with the document.write statement to display the following to the screen as output. Can anyone help? Just need help with the statement in javascript to write this:

Regular Pay: 35 hours @ $10/hour = $350

Am attaching my file thus far.

Thanks You!

Fred!

[upl-file uuid=4a25e8f5-7502-4fb6-b801-16b350a114e1 size=707B]ch4script5.txt[/upl-file]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 05.2004 — [font=arial]Without testing it, and as far as I know, this ought to work. Could you specify any problems you are having, in particular?

[b]Edit: I see your problem. Working on it...[/b][/font]

[font=monospace]

<script type="text/javascript">

var hours = parseInt(prompt("Enter the number of hours he or she worked that week:", ""));

var hourlyrate = parseFloat(prompt("Enter the hourly rate:", ""));

if (hours <= 40) {

var regular = (hours * hourlyrate.toFixed(2)); }

else {


var overtime = (regular + ((hours-40)*
hourlyrate/2)); }

document.write("Total Hours Worked: ", + hours);

</script>

[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@steelersfan88Mar 05.2004 — well, both scripts so far are wrong, because the regular variable can't be called in the else if it is defined in the if. should be more like:[code=php]<!--Fred Weigand-->
<!--MIS 241-300-->
<!--Spring 2004-->
<!--Scripting Exercise 5 Chapter 4 page 129-->

<html>
<head>
<title>Fred Weigand's Javascript for Chapter 4 Script Exercise #4</title>
</head>

<body>

<script language="JavaScript" type="text/javascript"><!--

var hours = prompt("Enter the number of hours he or she worked that week:", "");
var hourlyrate = prompt("Enter the hourly rate:", "");

var regular = hours * hourlyrate;
var overtime;

if (parseFloat(hours) > 40) {
overtime = parseFloat(regular) + ((hours-40) * (hourlyrate / 2));
}

document.write("Total Hours Worked: " + hours);
//-->

</script>

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@JonaMar 05.2004 — [font=arial]Yeah Steelersfan, I realized that after I looked at the code more thoroughly, which was the reason it took longer than expected to get the result he wanted.[/font]

[font=monospace]

<script type="text/javascript">

var regular = 0, overtime = 0;

var hours = parseInt(prompt("Enter the number of hours he or she worked that week:", ""));

var hourlyrate = parseFloat(prompt("Enter the hourly rate:", ""));

if (hours <= 40) {

regular = (hours * hourlyrate.toFixed(2)); }

else {

regular = (hours *
hourlyrate.toFixed(2));

overtime = regular + ((hours-40)* (hourlyrate/2)); }

document.write("Total Hours Worked: ", + hours +" @ $"+hourlyrate+"/hour = $"+regular);

</script>

[/font]

[b][J]ona[/b]
×

Success!

Help @fw_141 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.28,
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,
)...