How To Solve Codewars

How To Solve Codewars

As a self-taught developer, I am always looking for ways to improve my programming skills as it is important for me to consistently grow. One of the ways I do this is by using platforms like Codewars which allows me to challenge and improve my understanding of programming languages. However, approaching Codewars as a novice can be intimidating. If you can relate to this or have been having trouble solving the problems, check out the rest of the article below!

What is Codewars?

Codewars is an online platform that helps you learn and improve your programming skills by solving programming tasks. The difficulty of these tasks ranges from beginner to expert, making this a valuable platform for programmers of every level. Codewars also gives you the choice to choose between 58 programming languages. No matter what language you have experience in, this is a place where you can develop those skills or learn a new language altogether. Codewars also reward users when they answer tasks correctly, giving them the ability to "level up" and increasing the difficulty of each task as they do.

How to use it?

If you haven’t already, you can go to this link for instructions on how to register and use the platform.

https://docs.codewars.com/

How I solve Codewars (example)

Now that you are all signed in, I will show you how I approach every Codewars problem to answer it correctly. In this example, I have chosen to solve a programming task using Javascript and I chose a problem from level 8kyu which is the first level for beginners. Check out the problem below:

The first step for writing this program is to understand what we are trying to do. Fortunately for us, we know we are completing a function based on the code provided by Codewars:

The word "If" in the problem signals to me that we will probably be using a conditional statement. A conditional statement is used to perform different actions based on different conditions. This is the syntax of conditional statements:

if (condition is true) {
  //  block of code to be executed if the condition is true
}else {
  //  block of code to be executed if the condition is false
}

The first instruction listed in the problem says "If Alex gets 10 or more hoops, return the string "Great, now move on to tricks", which means on the condition that Alex gets 10 or more hoops, return the provided string. Based off the problem the "n" parameter in the function hoopCount is the number of times the hoop goes around. So we would write the conditional statement like this:

function hoopCount (n) {
   if (n >= 10) {
    return "Great, now move on to tricks"
    }
}

The code above is saying "if the amount of hoops (n) Alex gets is equal to or greater than at least 10, then return the string "Great, now move on to tricks". So far we have solved the first part of the coding problem. The second part states:

The second part of a conditional statement will only run if the first statement is not true as shown in the syntax below.

if (condition is true) {
  //  block of code to be executed if the condition is true
}else {
  //  block of code to be executed if the condition is false
}

So we know the next thing we would be telling the program is what to do if Alex does not get 10 hoops which is to return "Keep at it until you get it". Look below for the completed code:

function hoopCount (n) {
   if (n >= 10) {
    return "Great, now move on to tricks"
}else{
    return "Keep at it until you get it"
}

After submitting the code I received a message confirming that I "passed" and that my solution was correct.

Wrapping Up

I hope you were able to understand how breaking down the Codewars problem statement into small steps allowed me to solve it. Thank you for checking out the article and comment if you have any other tips to add!