Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,209,621 members, 8,006,628 topics. Date: Tuesday, 19 November 2024 at 09:00 AM |
Nairaland Forum / Science/Technology / Programming / HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? (1063 Views)
Devs How Are You Guys Making Money??? / So There Are Devs That Earn Up To 30k USD. / Help, Javascript Problem, (pictures Attached) (fixed) (2) (3) (4)
HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 1:53am On Aug 06, 2022 |
The two Else-ifs aren't working together. Each of them works if remove the other one. Only the last part works if I include both of them. Is there anything wrong with the syntax? Do you have a better way I can achieve the same result? Please help.
|
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by thug: 4:44am On Aug 06, 2022 |
Numbers and 11 cannot be strings. Remove the quotations marks..... 3 Likes |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by etoluw: 7:13am On Aug 06, 2022 |
MidasKinki: typeof inputPhone.value will always be a string whether you put number or string so typeof inputPhone.value != number will always be true if you need further explanations you can send whatsapp message |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by emmancipated(m): 7:32am On Aug 06, 2022 |
typeof inputPhone.value != Number inputPhone.value.length < 11 You can also just use <input type="number"> as the tag in your html if you expect just phone numbers and save your self some stress. 2 Likes |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by Anonime1105(m): 8:42am On Aug 06, 2022 |
MidasKinki: 1. "numbers" should be Number without the quote with a capital N 2. Remove the quote from "11", putting it in between quotes makes it a string instead of a number that it's supposed to be. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by etoluw: 8:59am On Aug 06, 2022 |
Anonime1105: Sir, the first paragraph is wrong typeof operator will return "number" when it is a number(primitive) 1 Like |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by jikins(m): 9:32am On Aug 06, 2022 |
emmancipated: Input type of number doesn't work as expected on Firefox from my experience and input generally returns a string no matter what you pass to it. Checking if the value is a number will always return false. op do if (isNaN(Number(inputPhone.value))) This worked for me in one of my projects. Also try using triple equal to instead of double if you can. Its minor but it reduces chances of bugs 1 Like |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 11:39am On Aug 06, 2022 |
thug: Thanks. I have effected the changes but still not working as intended. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 11:41am On Aug 06, 2022 |
etoluw: Thank you sir. Please how do I reach your whatsapp? |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 11:43am On Aug 06, 2022 |
jikins: Thanks Boss. I will try this out right away |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by JsScript: 3:16pm On Aug 06, 2022 |
MidasKinki:why don't you just use input type number in your HTML, instead of trying to check if input is a number or not |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by Nobody: 10:56pm On Aug 06, 2022 |
JsScript:I guess anything returned from the DOM will be of type string even if the input asks for numbers only. You’d still have to parse to int in your JS. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 11:51pm On Aug 06, 2022 |
JsScript: It's not a paid project. I just finished learning JS and tryna stretch my head. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by JsScript: 12:20am On Aug 07, 2022 |
MidasKinki:Happy stretching |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by Nobody: 12:25am On Aug 07, 2022 |
MidasKinki: Try explicitly stating the data type of your inputs e.g "Number()" |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by Xedmark: 10:04am On Aug 07, 2022 |
Uncle there's alot of error in your code than the problem you have. Firstly the pattern of your code is not clean and well written at all ....here's 2. There is an int that you declared as string value. Check something like "11" in your code 3. the "number" there is not suppose to be in bracket it's a string value so declare it with quotation mark. 4. Sincerely you don't need this long code to achieve this logic. U are only writing a program that checks if the input from the user is empty, a number or longer than 11 character. U are actually confused by the else if, why not use switch. 1 Like |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 10:19am On Aug 07, 2022 |
JsScript: Boss why na. LOL |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by emetisuccess(m): 11:46am On Aug 07, 2022 |
Have u been able to solve it, if no mention me here to solve it for u. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by Deicide: 2:04pm On Aug 07, 2022 |
MidasKinki:Where did you learn the JS from? A 2004 tutorial? |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 8:35pm On Aug 07, 2022 |
Deicide: No. Why? Is the code that dirty? Code geek, please tell me how to make it better. Don't just mock me. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by Deicide: 10:13pm On Aug 07, 2022 |
MidasKinki:I am not mocking you. The last time I see people use var for JS variable it's been long. Which probably means it's an old tutorial. use the "let" or "const" keyword instead. |
Re: HELP Javascript Devs! How Do I Re-write This If---else--if Statements To Run? by MidasKinki: 11:34pm On Aug 07, 2022 |
Deicide: Thanks. I'm grateful. |
(1) (Reply)
Download Windows 8 Preview The New Microsoft OS / Flash Game Help / Eclipse Pulsar And J2ME Res Issue
Viewing this topic: 1 guest(s)
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 27 |