Giter Site home page Giter Site logo

flw2-u1l2-23-24-student-exercises's Introduction

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!

flw2-u1l2-23-24-student-exercises's People

Contributors

cn-curriculum avatar cn-mika avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.