The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Random Number Game
Corey Cody
post Mar 9 2012, 11:05 AM
Post #1





Group: Members
Posts: 9
Joined: 8-September 11
Member No.: 15,352



I am a 18 year old student in my a Web design 2 class and I have been assigned a project to make a number game.

I created the first version of the game as instructed, using the number 7. but now I have to use math.random() and the function I have doesn't call the variable to print in the box.

I am attaching it to this and hope that you can help me fix it.


Attached File(s)
Attached File  guessinggame2.htm ( 724bytes ) Number of downloads: 216
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
XP1
post Mar 17 2012, 10:51 AM
Post #2





Group: Members
Posts: 7
Joined: 14-March 12
Member No.: 16,709



You should use
CODE
document.getElementById
and
CODE
===
.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Mar 18 2012, 11:40 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



QUOTE(XP1 @ Mar 17 2012, 04:51 PM) *

You should use
CODE
document.getElementById

and
CODE
===
.

I prefer getElementById too (since you don't need any <form> start- and end tags with it), but it's not necessary.

Regarding the === operator, the type of the OP's variable luckynumber is "number", and since browsers regard the types of form field values as strings the === operator will not work.


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
XP1
post Mar 19 2012, 02:11 AM
Post #4





Group: Members
Posts: 7
Joined: 14-March 12
Member No.: 16,709



QUOTE(Christian J @ Mar 18 2012, 12:40 PM) *
I prefer getElementById too (since you don't need any <form> start- and end tags with it), but it's not necessary.

Regarding the === operator, the type of the OP's variable luckynumber is "number", and since browsers regard the types of form field values as strings the === operator will not work.
Yes, it doesn't have to work like that, but it should. I'm not saying to make the changes as-is. Some code needs to be rewritten to follow good style. In the case of ===, it is good style to rewrite the expression so that the variables being compared were explicitly converted first. Implicit type coercion causes confusion especially among new programmers.

It is also a great idea to use a lint program to check for syntax and style correctness. For example, JSLint forces you to always write ===.
JSLint is one of the most useful tools when I am writing JavaScript.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th March 2024 - 10:41 PM