Skip to content

itscodenation/flw2-u1l2-23-24-student-exercises

Repository files navigation

Lesson 1.2: Variables & Conditionals

Welcome to the lesson on IDEs, Variables, and Conditionals! This README serves as a reference tool to review key points and includes code snippets to help reinforce learning.

Table of Contents:


Replit Introduction

IDEs

Let's begin by understanding what an IDE is. IDE stands for Integrated Development Environment, which is a software application providing a comprehensive set of tools for software development. It is the place where we can create and edit our code efficiently.

Key features of an IDE include:

  • Text Editor: Where you write your code.
  • Code Autocompletion: Suggests code snippets and functions to speed up coding.
  • Syntax Highlighting: Colors different elements of the code for better readability.
  • Debugger: Helps find and fix errors in the code.
  • Version Control: Allows tracking changes to code.

Replit & GitHub

Replit is an online IDE that enables coding in various programming languages directly from the browser. It offers a user-friendly and collaborative coding environment without requiring any installations.

Setting up a Replit account

  1. Go to www.replit.com.
  2. Click on 'Sign Up'.
  3. Choose the 'Continue with GitHub' option.
  4. Click on 'Authorize Replit'.

Forking from GitHub

  1. Find the Repo to Fork by going to the link provided for today's lesson.
  2. On the top right corner of the repo page, click the "Fork" button. This creates a copy of the repo in your GitHub account.
  3. Wait for the Fork to Complete, and you'll be redirected to the copied repo in your account.

Importing a Repo to Replit

  1. In Replit, click on the "+" icon on the top right corner and choose "Import from GitHub".
  2. Find and Copy the GitHub Repo URL by clicking the green "Code" button on GitHub and copying the URL.
  3. In Replit, paste the URL you copied from GitHub and click on the "Import from GitHub" button.
  4. Wait for the Import to Finish; it may take a few seconds or minutes.

Navigating Replit

  • Files: Displays the project files.
  • Tools: Various tools available for coding and managing the project.
  • Code Editor: The area where you write code.
  • Output: Shows your web page when you run the code.

Making/Saving Changes in Replit

Remember to press "Run" to see your code updates on the webpage. Projects autosave in your account. If you make changes and try to exit without running the code, you might receive an alert. In that case, press "Run" before exiting.


Variables in JavaScript

Variables are containers that store data values.

Declaring a Variable:

let box;

Assigning a Value to a Variable:

box = 10;
// or
let box = 10;

Re-assigning Value:

box = 15;  // Now, box has a value of 15

Note: Variable names should be descriptive, can't start with a number, and can't use JS keywords.


Technical Questions

  • Contextualize your question: explain what you're trying to achieve.
  • Specify the problem and indicate any solutions you've already tried.
  • Sharing your code can often help in resolving the issue faster.

Example: Instead of saying "My code doesn't work", you might say: "I'm trying to fetch user data from an API using JavaScript, but I'm getting a 404 error. I've checked the endpoint URL, and it seems correct. Can someone take a look at my fetch function?"


JavaScript Math

Basic arithmetic works intuitively:

5 + 2  // 7
5 * 2  // 10
5 - 2  // 3
5 / 2  // 2.5

Example with Variables:

let myNumber = 12;
myNumber / 3  // 4

Conditionals in JavaScript

Conditionals allow you to execute different code branches based on conditions.

Basic if Statement:

if (myNum === 8) {
    console.log("8 is great!");
}

if-else Statement:

if (myNum === 8) {
    console.log("8 is great!");
} else {
    console.log("That number is OK.");
}

if-else if-else Statement:

if (myNum === 8) {
    console.log("8 is great!");
} else if (myNum < 10) {
    console.log("Wow. Less than 10?");
} else {
    console.log("That number is OK.");
}

Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published