https://github.com/hasibcoderlab/javascript-conditional-and-ternary-operators
A collection of JavaScript examples demonstrating if-else statements and conditional (ternary) operators. Covers multiple real-world scenarios with ES6 features.
https://github.com/hasibcoderlab/javascript-conditional-and-ternary-operators
Last synced: 4 months ago
JSON representation
A collection of JavaScript examples demonstrating if-else statements and conditional (ternary) operators. Covers multiple real-world scenarios with ES6 features.
- Host: GitHub
- URL: https://github.com/hasibcoderlab/javascript-conditional-and-ternary-operators
- Owner: HasibCoderLab
- Created: 2025-02-13T17:29:16.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-13T17:57:58.000Z (about 1 year ago)
- Last Synced: 2025-02-13T18:36:50.858Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```js
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! 🚀