100 Days of Code: Day 60

Home / Technology / Web Development / 100 Days of Code: Day 60
I'm down to just one JavaScript project remaining before I am able to claim my certificate. 😲

[vc_row css=”.vc_custom_1526680382655{margin-top: 15px !important;margin-bottom: 60px !important;padding-right: 10% !important;padding-left: 10% !important;}”][vc_column][vc_progress_bar values=”%5B%7B%22label%22%3A%22Progress%22%2C%22value%22%3A%2260%22%2C%22color%22%3A%22blue%22%7D%5D” title=”100 Days of Code, Round 1″ percentage_value=”27″ title_color=”#3e3e3e” bar_color=”#1b7da9″ track_height=”20px” track_color=”#e7f6fc” m=”20″ extra_class=”” units=”%”][/vc_column][/vc_row][vc_row][vc_column][vc_custom_heading text=”Goals For Today:” font_container=”tag:h3|text_align:left” use_theme_fonts=”yes”][ultimate_icon_list icon_size=”16″ icon_margin=”20″][ultimate_icon_list_item icon_type=”custom” icon_img=”id^4091|url^https://www.blissfullemon.com/wp-content/uploads/2018/05/done.png|caption^null|alt^null|title^done|description^null”]Debug my code for the Roman Numeral Converter project[/ultimate_icon_list_item][ultimate_icon_list_item icon_type=”custom” icon_img=”id^4091|url^https://www.blissfullemon.com/wp-content/uploads/2018/05/done.png|caption^null|alt^null|title^done|description^null”]Try to complete one of the other JavaScript projects[/ultimate_icon_list_item][/ultimate_icon_list][vc_column_text]

Roman Numeral Converter

I’m going to start out today talking about the weirdness that is my code for the Roman Numeral Converter project. Remember yesterday when I said I couldn’t figure out why it was giving me different results every time I ran the tests? Yeah, it continued doing that today. I changed one line of code and poof all the tests passed.

It made me think of all those programmer memes that I’ve seen over the years.

Coding meme

Moving right along…

Two more projects are now complete!

After I got past the initial confusion of whatever my code was doing (because honestly, I couldn’t explain it even if I tried), I started working on the next JavaScript project, Caesar’s Cipher. I was thinking I would at least start it and finish tomorrow after I somehow broke that too.

Imagine my surprise when I finished the project with almost no problems at all and was able to move right into the Telephone Number Validator.

Spoiler Alert!

If you don’t want to see my solution to the Telephone Number Validator challenge, you may want to skip this part.

Return true if the passed string looks like a valid US phone number.Β The user may fill out the form field any way they choose as long as it has the format of a valid US number.

I want to share my code simply because it shows how powerful regular expressions can be. I was able to do something that would have required various loops through several lines of code to accomplish.

function telephoneCheck(str) {
     const formatReg = /^1?[-. ]?(([0-9]{3}))[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
     const formatReg2 = /^1?[-. ]?([0-9]{3})[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
     if (str.match(formatReg) || str.match(formatReg2)) {
          return true;
     } else {
          return false;
     }
}

telephoneCheck("1 555-555-5555");

This code works by taking two possible phone number combinations using regular expressions, formatRegΒ and formatReg2, then returned true if the string matches either of the possible combinations or false if it does not.

The first regular expression requires parenthesis surrounding the area code while the second does not allow parenthesis at all. That means the numbers “1 (555) 555-5555” or “555-555-5555” will pass, while the number “1(555-555-5555” will not as it does not contain the full set.

[/vc_column_text][/vc_column][/vc_row]

Let's chat!

%d bloggers like this: