Skip to content

A collection of JavaScript examples demonstrating if-else statements and conditional (ternary) operators. Covers multiple real-world scenarios with ES6 features.

Notifications You must be signed in to change notification settings

HasibCoderLab/JavaScript-conditional-and-ternary-operators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JavaScript Conditional and Ternary Operators

This repository contains various JavaScript examples showcasing if-else statements and the conditional (ternary) operator. It demonstrates multiple real-world use cases, including number checks, leap year determination, voting eligibility, and more.

πŸ“Œ Features

  • If-Else Statements: Covers different conditions with multiple cases.
  • Ternary Operator: Simplified conditional expressions.
  • ES6 Features: Arrow functions, template literals, and more.
  • Practical Examples: Number checks, leap years, voting eligibility, and more.

πŸš€ Examples

If-Else Statements

function checkNumber(num) {
    if (num > 0) {
        return "Positive";
    } else if (num < 0) {
        return "Negative";
    } else {
        return "Zero";
    }
}
console.log(checkNumber(10));  // Output: "Positive"

Ternary Operator

const checkNumber = (num) => num > 0 ? "Positive" : num < 0 ? "Negative" : "Zero";
console.log(checkNumber(-7));  // Output: "Negative"

πŸ“‚ File Structure

/project-root
│── script.js      # JavaScript logic
│── index.html     # HTML file to load the script
│── README.md      # Project documentation

πŸ› οΈ How to Use -**1.Clone this repository:

git clone https://github.com/HasibCoderLab/JavaScript-conditional-and-ternary-operators.git

-**2.Open index.html in a browser. -**3.Check the console for outputs.

πŸ“œ License This project is open-source and available under the MIT License.

Happy Coding! πŸš€

About

A collection of JavaScript examples demonstrating if-else statements and conditional (ternary) operators. Covers multiple real-world scenarios with ES6 features.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published