My path to learning Javascript

I’ve jumped around to a bunch of programming languages and I decided both through my own frustrations and the suggestions of my peers that I need to hone in on one language. It should be one that you intend to use in my future projects and a core language that sees lots of use in the real world. I decided to focus on learning Javascript, a language I’ve been flirting with for quite a while.

I found Javascript is Sexy had put together a very thorough plan of action to make the best use of your time. Many people in various Reddit programming subreddits had formed study groups to work through the course together. I kept missing a new starting group so I decided to just work through it on my own. Since I’ve been working with programming for a couple years now I began working through the “Study Guide for Experienced Developers” and picked up David Flanagan’s JavaScript: The Definitive Guide.

I worked through the first few weeks of the learning guide and just finished the first project, a dynamic quiz! The requirement was to start with a Javascript object that contained all of the questions of the quiz, and then show one question at a time and then show just the users score after the final question. We had to build the quiz in a way that would allow for any number of questions, and any number of answers for each question.

I decided to use vanilla Javascript and not use any jQuery. I will probably rebuild the quiz using jQuery before I move on to the next step in the project.

Here is my quiz in action:

See the Pen History Test by Anthony Skelton (@ajskelton) on CodePen.

It’s probably a little rough around the edges but it fulfills all of the requirements of the project. I peaked ahead and the next couple rounds of the project will be continuing to improve on this project.

Probably the hardest part for me to get through on this part of the project was getting the value of the answer provided and checking that against the correct answer. I was about to find some help and setup a function just to check the values, and then used that function as part of my checkScore function

function getRadioVal(form, name) {
  var val;
  var radios = form.elements[name];
  
  for (var i = 0, len = radios.length; i<len; i++) {
    if ( radios[i].checked ) {
      val = radios[i].value;
      break;
    }
  }
  return val;
}

function checkScore() {
  var val = getRadioVal(document.getElementById('test'), 'answer');
  if (val == allQuestions[counter].correctAnswer) {
    score++;
  } else {
    incorrect.push([counter, allQuestions[counter].choices[val]]);
    console.log(incorrect);
  }
}

I’ll do an update when I finish the next section of the project. Now back to more reading!


in

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *