Course: How To Make JS Your Own. Comparing Strings


I know this is an older track but I'm really enjoying the challenge and I only have two more lessons to go.

I have no idea how to go about this lesson. The instructions are a bit vague. Please help!


difficult challenge, so we have two strings, this and str:

String.prototype.compareTo = function(str, caseSensitive) {

which we need to compare, and if caseSensitive is set to true, the comparison should be case insensitive.


Thank you! Your hints helped me out.

Here's the solution I came up with. Please let me know if there's a more eloquent way to write this code:

String.prototype.compareTo = function(str, caseSensitive) {
	if(caseSensitive === true) {
	    return ((this == str) ? 0 : ((this > str) ? 1 : -1));
	} else {
	    return ((this.toUpperCase() == str.toUpperCase()) ? 0 : ((this.toUpperCase() > str.toUpperCase()) ? 1 : -1));


wow, nice code. I think it is really nice code

Can i recommend codewars to you? it has more nice challenges, i think you will enjoy it


I have been meaning to check out Codewars but I wasn't sure if my knowledge was up to par yet. I'll give it a shot!


you can give it a try, and if you like js challenge i can also highly recommend freecodecamp, just skip the html and stuff, just do the javascript, also a great challenge and learning source.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.