Posts

Showing posts with the label javascript

JS function challenges

Image
Alright, today I am halfway done going through the basics, and now the course has reached practical assignment bit. Time to write some code independently! Task 1: password validator: The below (Colt's solution) would have been sufficient: function isValidPassword ( password , username ) { if ( password . length < 8 ) { return false ; } if ( password . indexOf ( ' ' ) !== - 1 ) { return false ; } if ( password . indexOf ( username ) !== - 1 ) { return false ; } return true ; } But I wanted to take it a bit further with the messaging. After all, in real life projects, the user wants to know WHY her input was not accepted , right? Trickiest part was to figure out how to inform the user if multiple conditions about their passwords were incorrect. I began with making a standard loop with if+else if and then realised the code looks no further as the first condition is met. Ugh. So, this is what I came up with in the e...

Brushing dust from Javascript basics

Image
Aaaand off I go with the Javascript course! I sure am missing my dual screen set up back home, so I improvised with my tablet which I now use to play the Udemy video. Feels nice to make some basic scripts and loops. With reinstalling Windows some of my VS set-up went missing, so today I rediscovered Live Server plugin which makes coding a dream. Every time you save a HTML/CSS/JS file it automatically refreshes your html to see the effects. I split my screen, allowing me to see the new script logs immediately. Since I went through JS in the original Bootcamp, I pretty much skim through the basics. I don't want to skip them entirely since it does not feel intuitive anymore to write basic JS and also because Colt uses really cool examples of illustrating the methods. First time I've used indexOf method to evaluate if a string includes a forbidden character for example (visible on the screenshot above). "How absolutely marvellous" , I say, while sipping coffee. ...