About   Users   Help
Users & Guests Online
On Page: 1
Directory: 1 & 83
Entire Site: 6 & 1031
Page Staff: tgags123, pokemon x, tgags123, supercool22, SonicOlmstead, SonicOlmstead, Barathemos, Furret,
05-18-26 06:34 PM

Forum Links

Related Threads
Coming Soon

Thread Information

Views
1,343
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: 512
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: 140


POSTS: 5567/5719
POST EXP: 366194
LVL EXP: 33113202
CP: 14760.6
VIZ: 1538669

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.

--------------------
Life goes on

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: 542 days
Last Active: 535 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: 99


POSTS: 785/2501
POST EXP: 108718
LVL EXP: 9874978
CP: 8695.1
VIZ: 87106

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.
Vizzed Elite

Vizzed #1 Castlevania Fan.
Vizzed #1 British Furry


Affected by 'Laziness Syndrome'

Registered: 04-24-09
Location: England
Last Post: 4178 days
Last Active: 4139 days

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

tRIUNE
Level: 195


POSTS: 7471/12374
POST EXP: 624776
LVL EXP: 105033153
CP: 241072.3
VIZ: 7097791

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: 1719 days
Last Active: 1698 days

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

silverthundr
Level: 102


POSTS: 2686/2808
POST EXP: 132342
LVL EXP: 10947557
CP: 4426.7
VIZ: 20673

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: 3939 days
Last Active: 162 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: 140


POSTS: 5568/5719
POST EXP: 366194
LVL EXP: 33113202
CP: 14760.6
VIZ: 1538669

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

--------------------
Life goes on

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: 542 days
Last Active: 535 days

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

GuardianZack
Level: 66


POSTS: 489/1059
POST EXP: 115694
LVL EXP: 2447424
CP: 20466.0
VIZ: 464421

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: 4579 days
Last Active: 4575 days

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

silverthundr
Level: 102


POSTS: 2688/2808
POST EXP: 132342
LVL EXP: 10947557
CP: 4426.7
VIZ: 20673

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: 3939 days
Last Active: 162 days

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

BNuge
Level: 140


POSTS: 5570/5719
POST EXP: 366194
LVL EXP: 33113202
CP: 14760.6
VIZ: 1538669

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.

--------------------
Life goes on

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: 542 days
Last Active: 535 days

Page Comments

Dove4JS - 12-12-20 05:26 AM
no image
joldboy70 - 07-10-20 11:13 AM
test
joldboy70 - 07-10-20 11:12 AM
test
savage23157 - 04-08-20 01:33 PM
Hi im new vizzed
zokuza - 11-18-19 09:08 AM
final got playstaion games unlock yes baby digimon world here i com
yoshirulez! - 02-10-17 08:45 PM
MAY MAYS
yoshirulez! - 02-10-17 08:45 PM
maymays
yoshirulez! - 02-07-17 11:13 PM
OwO what's this?
yoshirulez! - 02-07-17 11:13 PM
OwO what's this?
yoshirulez! - 02-07-17 11:13 PM
OwO what's this?

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.

×