₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,092 members, 8,420,272 topics. Date: Thursday, 04 June 2026 at 03:18 PM

Toggle theme

Help With A Javascript Code - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingHelp With A Javascript Code (1304 Views)

1 Reply (Go Down)

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"wink;
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"wink }
}
//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:
as long as the two strings contain the same sequence of characters, checkEqual will be true.
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):
nelsonchrisx:
wow... thanks bro, i guess me.toUpperCase === userGuess.toUpperCase converts the two strings to upper case value
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:
wow... thanks bro, i guess me.toUpperCase === userGuess.toUpperCase converts the two strings to upper case value
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:
Dude, ever heard of jQuery?
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:
Yeah exactly....I be lady o lol.
Hello, please can I pm you?
Re: Help With A Javascript Code by alexisSr(f): 9:28am On Oct 31, 2016
gidimasters:
Hello, please can I pm you?
Sure why not.
1 Reply

Need Someone To Help With My Javascript CodeWhat To Learn Before A Javascript FrameworkJavascript Code Not Performing Its Functionality234

Are You A Programmer? Answer This NCT Coding Questions!.DBF Format FileAre You A Programmer Or Fintech Start Up? Then You Must Read This