| Z feng (57) | |||
My friend asked me to look at the code of JavaScript she did why it is wrong, I didnt learn JavaScript, so could anyone help, it should be very easy JavaScript code:
Thanks! | |||
|
Last edited on
|
|||
| Z feng (57) | |
| It asked user to input 5 numbers and display the max one | |
|
|
|
| firedraco (5413) | |
| There is no item on the page with the id "resultAsNumber". | |
|
|
|
| Z feng (57) | |
|
what's setoutput about? I thought it's the function of set output | |
|
Last edited on
|
|
| Z feng (57) | |
| It might be wrong to use that function tho, but how to fix it? | |
|
|
|
| Athar (4376) | ||
fourth is misspelled twice. And that sort of problem is what arrays are for.
You add the element? It's not "wrong" to use the function per se. | ||
|
Last edited on
|
||
| Z feng (57) | |
|
lol that's my bad. I fixed that part, ty for pointing out. I don't think they even learn anything about array. That's just a really basic CS class. It still cant run. Any other problem? | |
|
|
|
| iseeplusplus (297) | |||
Also need these ; at the end of statements
| |||
|
|
|||
| Z feng (57) | |
| ok, fixed ";". Anything else? | |
|
|
|
| Athar (4376) | |
| Well, have you finally added an element with the id "resultAsNumber"? | |
|
|
|
| Z feng (57) | |||
it's here, in the function:
Don't know whether it's right way to use the function or not. And 60-61 code line of the original one | |||
|
Last edited on
|
|||
| James2250 (245) | |
I don't really use Javascript but.. Max value:<document.write("resultAsNumber")> This isn't going to do the correct thing (as has been mentioned here before). In the calculate function it is trying to reference an element by the id "resultAsNumber" which hasn't been defined anywhere in html. You will want to replace that document.write("resultAsNumber") with something like. Max Value: <input type ="text" id ="resultAsNumber"> That is creating an input box with an id of resultAsNumber which can then be changed by the setOutput function above. (Also the code is spelling fourth differently as times, double check those or it wont work). | |
|
Last edited on
|
|
| Z feng (57) | |
|
OK, I did change the fourth and ; problems. And I tried <input type ="text" id ="resultAsNumber">, just wanna know what's "text" about? And it's still not working :(
| |
|
Last edited on
|
|
| iseeplusplus (297) | ||||
| ||||
|
Last edited on
|
||||
| James2250 (245) | |||
|
It works correctly for me once I make both of those changes I mentioned (pretty sure the ; is optional as I don't add them, but it doesn't hurt to have them). Make sure you change both of the spelling mistakes so it looks like this.
The "text" just specifies it's a textbox but it doesn't have to be included. If it still doesn't work after you have double checked that stuff, post again or edit your post and I can look. | |||
|
|
|||
| Z feng (57) | |||
This is the code right now
| |||
|
Last edited on
|
|||
| Z feng (57) | |
| It didnt display the max after I click "Go" | |
|
|
|
| James2250 (245) | |||
You have somehow managed to get rid of the closing parameter bracket on the setOutput function. Change it to how it was originally.
Also the ; should be inside the function, not outside of it. | |||
|
|
|||
| Athar (4376) | ||
Just read what your Javascript console is displaying:
| ||
|
|
||
| Z feng (57) | |
|
Thank you very much! It's runing good! Because I am studying C++, like I just said, it's my friend's code, I can only help her logic, but can't help the codes, i even didnt have the compiler to compile this JavaScript, I just pick up an online instant compiler to run the program! Thank you very much for your guys help! I really appreciate! | |
|
|
|