From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Error messages

Solution: Error messages - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Solution: Error messages

(upbeat music) - [Instructor] So now I'm going to show you how I solve this challenge. I want to emphasize, again, that this is just one of the many ways that it could've been done. You might've done it differently, and that's probably just as good. So first let's decide what our input criteria is going to look like. I decided that when I was solving this problem, each of these was going to contain a series of functions. To do an example now, we'll just do one function, but I decided that this function was going to take one argument, which is the current value of this field, up in our current input values object, and these functions were going to test something. So for example, for our first name, we want to test if the length of the value, value.length, is greater than or equal to two. And then if this was true, I wanted to return just an empty string, and if it was false, I wanted to return an error message. So we can say first name must be at least two characters. And note that I…

Contents