My learning journey to Javascript -Week 2
Tags: javascript, beginners, programming, opensource
Published: 2023-02-16 13:40:02

Week -2
#programming #beginners #javascript #computerscience #womenintech

This week, I learned about functions in JavaScript, and I must say, it was quite an interesting experience. I discovered several types of functions, including function concise, function expression, and function declaration.

Functions are a big part of coding, and they're like little tools that we can use to solve problems. You can think of them like Lego blocks that we can put together to build something cool.

There are a few different types of functions in JavaScript, but they all do basically the same thing: they take some input (like numbers or text), and they give us an output (like a result or a message).

One type of function is called a "function expression." This just means that we give the function a name and then use that name like a tool whenever we need it. It's kind of like a hammer that we keep in our toolbox and take out when we need to nail something.

Another type of function is called a "function declaration." This is where we use the word "function" to tell the computer that we're creating a function. It's like telling the computer, "Hey, I'm going to build a new tool here!" And then we give that tool a name and tell it what to do.

We can also use something called an "arrow function," which is just a shorter way of writing a function. This is like a shorthand way of building a tool that we can use to solve a problem quickly and easily.

To use these tools, we "call" the function by using its name and giving it some input. For example, if we have a function that adds two numbers together, we can call it like this:

function addNumbers(num1, num2) {

return num1 + num2;

}

const result = addNumbers(3, 5);

console.log(result);

This code will print the number 8 to the console, because we're calling the addNumbers function with the input values of 3 and 5.

If you're just starting out with coding, it can be really helpful to practice using functions by building small projects. One fun project that you can try is creating a Rock Paper Scissors game. You can use functions to define the rules of the game and to keep track of the score.

Remember, functions are just tools that we use to solve problems. By learning how to use them, you can start building your own programs and solving your own coding challenges. And if you're ever stuck or need help, there are always resources available, like online tutorials or coding communities, that can help you along the way.

I got to practice my learning through a fun project, Rock, Paper & Scissors game.

For those who may not be familiar with it, Rock Paper Scissors is a classic game where two players each choose one of three options: rock, paper, or scissors. The winner is determined based on a set of rules: rock beats scissors, scissors beat paper, and paper beats rock.

To build the game, I used functions to define the rules of the game and to keep track of the score. I also used conditional statements (like "if" and "else" statements) to check which player won and to update the winner accordingly.

The code was broken into 4 parts :

Get the user's choice

Get the computer's choice

Compare the two choices and determine a winner

Start the program and display results.

One thing I learned through this project is that coding can be a bit like playing a game of Rock Paper Scissors. You have to think about all the different possible outcomes and plan for them accordingly. Just like in the game, there are a lot of different moves you can make in coding, and it's important to choose the right one for the situation.

Another thing I learned is that coding is a lot like learning a new language. There are a lot of new words and concepts to learn, but once you start to understand them, you can use them to create your own programs and express your ideas in a whole new way.

Overall, the Rock Paper Scissors project was a really fun and rewarding way to put my coding skills to the test. By working on this project, I was able to solidify my understanding of functions and other key programming concepts, and I'm excited to continue building my coding skills in the future.

Any suggestions and feedback are most welcome, Thanks!