Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,207,852 members, 8,000,596 topics. Date: Tuesday, 12 November 2024 at 12:29 PM |
Nairaland Forum / Science/Technology / Programming / Help With A Javascript Code (1202 Views)
Need Someone To Help With My Javascript Code / What To Learn Before A Javascript Framework / Javascript Code Not Performing Its Functionality (2) (3) (4)
Help With A Javascript Code by Nobody: 3:00pm On Oct 30, 2016 |
Good P.M gurus and guruine's pls who can help me out with this code. How can i use regExp to make a userguess case-insensitive if correct. e.g <!doctype html> <html> <head> bla bla bla </head> <body> <h1> Guess A Month </h1><label for = "guess"> Input your Guess </label> <input id = "guess" type = "text"> <button type = "button"> Click to Submit Guess </button> <script> var me = document.getElementById("guess" function guessMonth() { var myMonth = ["January", "February", "March",....//up to December] var randomGuess = Math.floor(Math.random() * 12) + 1 var userGuess = myMonth[randomGuess]; if (me.value == userGuess) {window.alert("Congratulations" } } //ll still add other functionalities, but this is where my problem lies </script> </body> </html> my question is now, how can i write the code so that if the user inputs JANUARY or january or JAnuARY or so... he will still be correct if the guessed value was "January" as contained in the array. pls i would really appreciate your answers |
Re: Help With A Javascript Code by alexisSr(f): 3:21pm On Oct 30, 2016 |
var checkEqual = me.toUpperCase()===user.toUpperCase() 1 Like |
Re: Help With A Javascript Code by alexisSr(f): 3:22pm On Oct 30, 2016 |
as long as the two strings contain the same sequence of characters, checkEqual will be true. |
Re: Help With A Javascript Code by Nobody: 3:35pm On Oct 30, 2016 |
alexisSr:wow... thanks bro, i guess me.toUpperCase === userGuess.toUpperCase converts the two strings to upper case value |
Re: Help With A Javascript Code by alexisSr(f): 3:39pm On Oct 30, 2016 |
nelsonchrisx:Not explicitly. It checks whether the two values when converted to uppercase are equal. The actual values of both variables will remain unchanged....I be lady o lol. 1 Like |
Re: Help With A Javascript Code by noordean(m): 4:50pm On Oct 30, 2016 |
nelsonchrisx: Don't forget, it's not the element "me" itself u are converting to uppercase, but rather the value of the element. |
Re: Help With A Javascript Code by SeunLanLege(m): 5:31pm On Oct 30, 2016 |
Dude, ever heard of jQuery? |
Re: Help With A Javascript Code by noordean(m): 6:14pm On Oct 30, 2016 |
SeunLanLege:As a beginner, I think one needs to build the foundation before moving to these libraries. Or what do u think? 2 Likes |
Re: Help With A Javascript Code by gidimasters(m): 6:44pm On Oct 30, 2016 |
alexisSr:Hello, please can I pm you? |
Re: Help With A Javascript Code by alexisSr(f): 9:28am On Oct 31, 2016 |
gidimasters:Sure why not. |
(1) (Reply)
Are You A Programmer? Answer This NCT Coding Questions! / I Need A Good Programmer/javascript Guru In Abeokuta For Quick Job / A Professional Web Designer Is Needed In Enugu Urgently
(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. 16 |