Help With A Javascript Code - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Help With A Javascript Code (1304 Views)
| 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() |
| 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*. Modified: 10:09am On Oct 31, 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. |
| 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? |
| 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. |
Need Someone To Help With My Javascript Code • What To Learn Before A Javascript Framework • Javascript Code Not Performing Its Functionality • 2 • 3 • 4
Are You A Programmer? Answer This NCT Coding Questions! • .DBF Format File • Are You A Programmer Or Fintech Start Up? Then You Must Read This
;