Skip to main content

Setting defalt parameters in Javascript

Learnt something new today. To set default parameters, should no input be given, check if type of variable is undefined. If it is, define default parameters.  Perhaps I have already learnt this but it has left my memory stores. I think this is new information to my brain though. Pretty cool! Thanks to edabit.com , my new favourite site <3 <3 <3
function moodToday(mood) {
mood = typeof mood != 'undefined' ? mood : "neutral"; 
return ("Today, I am feeling " + mood);
}

Comments

Popular posts from this blog

So long and thanks for all the fish! Part 1 of 2

I have been with the Tech Academy both as a software developer bootcamp student, as well as an employee. After my bootcamp, I was hired first as the live project instructor, and then as Live Project Director. This, I believe, gives me a unique point of view. I have absolutely no regrets and would join the bootcamp again. But there are a number of things I would do differently. What I have learnt as a former student 1. DO NOT WORK PART TIME.   I worked part-time(20-30hrs) during my bootcamp. I was up at 2.30-3.00am every day to work for several hours. I took a short nap, and then I took a 1hr bus ride down to campus. Studied for 7- 9 hours. Took a 1hr bus ride back home. Lather, rinse, repeat. I also had some family obligations. My weekends and half the summer were taken up caring for my young stepdaughter. I was completely exhausted by the end of the bootcamp and I didn't know if I could do more. Learning to program is HARD. You need to be fully focused. I am fortunate because I di...

Shortcuts

 I saw one of my colleagues do something magical. He automatically fixed the alignment of student code on Visual Studio with just 1 little keyboard shortcut. Ctrl-k, followed by D. Holding down Ctrl the entire time Sometimes shortcuts really do work and make your life better!   

Using Modals to render forms

A student wanted to create several tables with foreign keys linking them. He was placing the forms all over the place and that just didn't seem to make sense to me. I suggested that he link all the forms to one main registration page, and while he worked on it, I came up with my own solution that I feel rather proud of. Though I'm well aware it is a very simple solution.  views.py def register (request): # form for team formteam = TeamForm(request.POST or None ) if formteam.is_valid(): formteam.save() return redirect( 'registerForTeam' ) else : print (formteam.errors) formteam = TeamForm() # form for coach formcoaches = CoachesForm(request.POST or None ) if formcoaches.is_valid(): formcoaches.save() return redirect( 'registerForTeam' ) else : print (formcoaches.errors) formcoaches = CoachesForm() # form for player formplayer = PlayersForm(request.POST or None ...