Remove Ad, Sign Up
Register to Remove Ad
Register to Remove Ad
Remove Ad, Sign Up
Register to Remove Ad
Register to Remove Ad
Signup for Free!
-More Features-
-Far Less Ads-
About   Users   Help
Users & Guests Online
On Page: 1
Directory: 95
Entire Site: 7 & 1097
Page Staff: pokemon x, pennylessz, Barathemos, tgags123, alexanyways, supercool22, RavusRat,
05-06-24 11:00 AM

Forum Links

Related Threads
Coming Soon

Thread Information

Views
929
Replies
7
Rating
0
Status
CLOSED
Thread
Creator
BNuge
04-11-13 05:57 PM
Last
Post
BNuge
04-16-13 11:12 AM
Additional Thread Details
Views: 281
Today: 0
Users: 0 unique

Thread Actions

Thread Closed
New Thread
New Poll
Order
 

Help with a Javascript Assignment

 

04-11-13 05:57 PM
BNuge is Offline
| ID: 777152 | 265 Words

BNuge
Level: 138


POSTS: 5567/5714
POST EXP: 365399
LVL EXP: 30905077
CP: 14425.8
VIZ: 1505287

Likes: 0  Dislikes: 0
So I had to do a basic Javascript assignment that includes a certain if/else statement. For some reason when it should display the "if" result, it shows the "else" result and vice versa. Can anyone figure out where I went wrong? My college professor was messing around with it for a while, but couldn't figure out the problem.

I used w3schools when learning how to code an if/else statement-

http://www.w3schools.com/js/js_if_else.asp


Here's the code. I'm removing the brackets around the html, script, and br tags, so make sure you put those brackets in before testing.

html
script type="text/javascript"
var number1 = 0;
var number2 = 0;
var number3 = 0;
var pay1 = 0;
var pay2 = 0;
number1 = prompt("Enter the number of hours the employee worked",0);
number2 = prompt("Enter the number of hours the employee is contracted to work before overtime",0);
number3 = prompt("Enter the pay per hour",0);
pay1 = number1 * number3;
pay2 = number3 * (2 * number1 - number2);
document.write("The employee worked ",number1," hours");
document.write("br");
document.write("The employee was contracted to work ",number2," hours");
document.write("br");
if (number1 > number2)
{
document.write("The employee worked more than their contracted hours");
document.write("br");
document.write("The employee's pay is ",pay2);
}
else
{
document.write("The employee worked within their contracted hours");
document.write("br");
document.write("The employee's pay is ",pay1);
}
/script
/html


I considered asking in this thread, but that would be a 7 month bump so I decided to make my own thread-

https://www.vizzed.com/boards/thread.php?id=11418


Potentially useful summons-

tRIUNE :
GuardianZack :
silverthundr :
Lazlo Falconi :


If anyone wants to summon someone I forgot about, feel free to do so.
So I had to do a basic Javascript assignment that includes a certain if/else statement. For some reason when it should display the "if" result, it shows the "else" result and vice versa. Can anyone figure out where I went wrong? My college professor was messing around with it for a while, but couldn't figure out the problem.

I used w3schools when learning how to code an if/else statement-

http://www.w3schools.com/js/js_if_else.asp


Here's the code. I'm removing the brackets around the html, script, and br tags, so make sure you put those brackets in before testing.

html
script type="text/javascript"
var number1 = 0;
var number2 = 0;
var number3 = 0;
var pay1 = 0;
var pay2 = 0;
number1 = prompt("Enter the number of hours the employee worked",0);
number2 = prompt("Enter the number of hours the employee is contracted to work before overtime",0);
number3 = prompt("Enter the pay per hour",0);
pay1 = number1 * number3;
pay2 = number3 * (2 * number1 - number2);
document.write("The employee worked ",number1," hours");
document.write("br");
document.write("The employee was contracted to work ",number2," hours");
document.write("br");
if (number1 > number2)
{
document.write("The employee worked more than their contracted hours");
document.write("br");
document.write("The employee's pay is ",pay2);
}
else
{
document.write("The employee worked within their contracted hours");
document.write("br");
document.write("The employee's pay is ",pay1);
}
/script
/html


I considered asking in this thread, but that would be a 7 month bump so I decided to make my own thread-

https://www.vizzed.com/boards/thread.php?id=11418


Potentially useful summons-

tRIUNE :
GuardianZack :
silverthundr :
Lazlo Falconi :


If anyone wants to summon someone I forgot about, feel free to do so.
Vizzed Elite
Third Place in Feb 2011 VCS Achieved Ravering Syndrome + on Jan 6, 2012


Affected by 'Laziness Syndrome'

Registered: 04-30-10
Location: Northeast US
Last Post: 1230 days
Last Active: 455 days

(edited by BNuge on 04-11-13 06:00 PM)    

04-11-13 06:00 PM
Tails the Fox is Offline
| ID: 777156 | 28 Words

Tails the Fox
Level: 97


POSTS: 785/2501
POST EXP: 108718
LVL EXP: 9268366
CP: 8686.1
VIZ: 86206

Likes: 0  Dislikes: 0
If the 'if' and 'else' results are getting switched, try switching the two of them. I'm sorry. My Javascript knowledge is dreadful. I'm more of a css guy.
If the 'if' and 'else' results are getting switched, try switching the two of them. I'm sorry. My Javascript knowledge is dreadful. I'm more of a css guy.
Vizzed Elite

Vizzed #1 Castlevania Fan.
Vizzed #1 British Furry


Affected by 'Laziness Syndrome'

Registered: 04-24-09
Location: England
Last Post: 3436 days
Last Active: 3396 days

04-11-13 06:16 PM
tRIUNE is Offline
| ID: 777176 | 59 Words

tRIUNE
Level: 192


POSTS: 7471/12374
POST EXP: 624776
LVL EXP: 98109794
CP: 240947.9
VIZ: 7093601

Likes: 0  Dislikes: 0
What's it supposed to do?

I get:

- Enter the number of hours the employee worked
*OK / Cancel

- Enter the number of hours the employee is contracted to work before overtime
*Prevent this page from creating additional dialogs
*OK / Cancel

- Enter the pay per hour
*Prevent this page from creating additional dialogs
*OK / Cancel
What's it supposed to do?

I get:

- Enter the number of hours the employee worked
*OK / Cancel

- Enter the number of hours the employee is contracted to work before overtime
*Prevent this page from creating additional dialogs
*OK / Cancel

- Enter the pay per hour
*Prevent this page from creating additional dialogs
*OK / Cancel
Vizzed Elite
Former Admin

Hero of Hyrule


Affected by 'Laziness Syndrome'

Registered: 06-09-10
Last Post: 977 days
Last Active: 955 days

04-11-13 06:38 PM
silverthundr is Offline
| ID: 777192 | 49 Words

silverthundr
Level: 100


POSTS: 2686/2808
POST EXP: 132342
LVL EXP: 10169249
CP: 4425.2
VIZ: 20523

Likes: 0  Dislikes: 0
First of all, "document.write" is apparently bad practice. However, that's not what you asked.

Secondly, I was able to get it to work fine.




This is with 44,40,9 and 40,40,9 by the way.

EDIT - I just plugged the code in, added the <>'s, and uploaded to my site.
First of all, "document.write" is apparently bad practice. However, that's not what you asked.

Secondly, I was able to get it to work fine.




This is with 44,40,9 and 40,40,9 by the way.

EDIT - I just plugged the code in, added the <>'s, and uploaded to my site.
Vizzed Elite
Not Here


Affected by 'Laziness Syndrome'

Registered: 07-23-11
Location: OUTTA HERE
Last Post: 3196 days
Last Active: 1041 days

(edited by silverthundr on 04-11-13 06:41 PM)    

04-12-13 12:27 AM
BNuge is Offline
| ID: 777408 | 63 Words

BNuge
Level: 138


POSTS: 5568/5714
POST EXP: 365399
LVL EXP: 30905077
CP: 14425.8
VIZ: 1505287

Likes: 0  Dislikes: 0
tRIUNE :
silverthundr :

I used 10,8,8 and got this-

The employee worked 10 hours
The employee was contracted to work 8 hours
The employee worked within their contracted hours
The employee's pay is 80


8,10,8 gave me this-

The employee worked 8 hours
The employee was contracted to work 10 hours
The employee worked more than their contracted hours
The employee's pay is 48
tRIUNE :
silverthundr :

I used 10,8,8 and got this-

The employee worked 10 hours
The employee was contracted to work 8 hours
The employee worked within their contracted hours
The employee's pay is 80


8,10,8 gave me this-

The employee worked 8 hours
The employee was contracted to work 10 hours
The employee worked more than their contracted hours
The employee's pay is 48
Vizzed Elite
Third Place in Feb 2011 VCS Achieved Ravering Syndrome + on Jan 6, 2012


Affected by 'Laziness Syndrome'

Registered: 04-30-10
Location: Northeast US
Last Post: 1230 days
Last Active: 455 days

04-12-13 04:58 AM
GuardianZack is Offline
| ID: 777479 | 45 Words

GuardianZack
Level: 65


POSTS: 489/1059
POST EXP: 115694
LVL EXP: 2260150
CP: 20266.3
VIZ: 445887

Likes: 0  Dislikes: 0

BNuge : It all looks fine to me, also. The only other thing I could suggest, would be to use a developer tool to look over the script for errors. It can be the simplest of things, sometimes. I always forget to close my brackets, personally.

BNuge : It all looks fine to me, also. The only other thing I could suggest, would be to use a developer tool to look over the script for errors. It can be the simplest of things, sometimes. I always forget to close my brackets, personally.
Vizzed Elite


Affected by 'Laziness Syndrome'

Registered: 07-27-12
Location: Knoxville, TN
Last Post: 3837 days
Last Active: 3833 days

04-12-13 06:08 PM
silverthundr is Offline
| ID: 777885 | 15 Words

silverthundr
Level: 100


POSTS: 2688/2808
POST EXP: 132342
LVL EXP: 10169249
CP: 4425.2
VIZ: 20523

Likes: 0  Dislikes: 0
BNuge : Where are you testing this? As far as I can tell, it works fine.
BNuge : Where are you testing this? As far as I can tell, it works fine.
Vizzed Elite
Not Here


Affected by 'Laziness Syndrome'

Registered: 07-23-11
Location: OUTTA HERE
Last Post: 3196 days
Last Active: 1041 days

04-16-13 11:12 AM
BNuge is Offline
| ID: 780178 | 19 Words

BNuge
Level: 138


POSTS: 5570/5714
POST EXP: 365399
LVL EXP: 30905077
CP: 14425.8
VIZ: 1505287

Likes: 0  Dislikes: 0
silverthundr :

I have the code saved in an htm file and I tried running it in IE and Firefox.
silverthundr :

I have the code saved in an htm file and I tried running it in IE and Firefox.
Vizzed Elite
Third Place in Feb 2011 VCS Achieved Ravering Syndrome + on Jan 6, 2012


Affected by 'Laziness Syndrome'

Registered: 04-30-10
Location: Northeast US
Last Post: 1230 days
Last Active: 455 days

Links

Page Comments


This page has no comments

Adblocker detected!

Vizzed.com is very expensive to keep alive! The Ads pay for the servers.

Vizzed has 3 TB worth of games and 1 TB worth of music.  This site is free to use but the ads barely pay for the monthly server fees.  If too many more people use ad block, the site cannot survive.

We prioritize the community over the site profits.  This is why we avoid using annoying (but high paying) ads like most other sites which include popups, obnoxious sounds and animations, malware, and other forms of intrusiveness.  We'll do our part to never resort to these types of ads, please do your part by helping support this site by adding Vizzed.com to your ad blocking whitelist.

×