|
1 |
| -# 22 - Pass Fail |
| 1 | +# ⭐ Star Pattern Programs (JavaScript) |
2 | 2 |
|
3 |
| -## ✅ Objective |
4 |
| -Check whether a student has passed or failed based on marks. |
| 3 | +This folder contains **10 JavaScript programs** to print different star and number patterns. |
| 4 | +These exercises help in building strong **looping logic** and practicing **nested loops** in JavaScript. |
5 | 5 |
|
6 |
| -## 💡 Concepts Used |
7 |
| -- Variables in JavaScript (`let`) |
8 |
| -- Conditional statements (`if-else`) |
9 |
| -- Comparison operator (`>=`) |
10 |
| -- Console output (`console.log()`) |
| 6 | +--- |
11 | 7 |
|
12 |
| -## 📘 Code Explanation |
13 |
| -The program declares a variable `marks` with the value `60`. |
14 |
| -- If `marks >= 50`, it prints **"Pass"**. |
15 |
| -- Otherwise, it prints **"Fail"**. |
| 8 | +## ✅ Objectives |
| 9 | +- Understand **loop control** for rows and columns. |
| 10 | +- Practice **nested `for` loops** to build patterns. |
| 11 | +- Learn alignment using `" ".repeat()` and `"*".repeat()`. |
| 12 | +- Strengthen problem-solving through **pattern design**. |
16 | 13 |
|
| 14 | +--- |
| 15 | + |
| 16 | +## 📂 Files in this Folder |
| 17 | + |
| 18 | +1. **Right_Angled_Triangle.js** → Right-aligned right-angled triangle of stars. |
| 19 | +2. **Pyramid.js** → Pyramid of stars. |
| 20 | +3. **Inverted_Triangle.js** → Inverted triangle of stars. |
| 21 | +4. **Number_Triangle.js** → Increasing number triangle. |
| 22 | +5. **Number_Pyramid.js** → Right-aligned number pyramid. |
| 23 | +6. **Number_Full_Pyramid.js** → Full pyramid with numbers. |
| 24 | +7. **Palindrome_Number_Pyramid.js** → Palindrome number pyramid. |
| 25 | +8. **Hollow_Square.js** → Hollow square star pattern. |
| 26 | +9. **X_Pattern.js** → X shape pattern using stars. |
| 27 | +10. **Diamond.js** → Diamond star pattern. |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## 💡 Concepts Practiced |
| 32 | +- `for` loops (row iteration) |
| 33 | +- Nested `for` loops (row × column control) |
| 34 | +- String manipulation (`repeat`, concatenation) |
| 35 | +- Printing aligned output with `console.log()` |
| 36 | +- Pattern symmetry (top/bottom halves, left/right alignment) |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## 📘 Example: Diamond Pattern (10_Diamond.js) |
| 41 | + |
| 42 | +### Code |
17 | 43 | ```javascript
|
18 |
| -// Write a program to check pass or fail based on marks. |
| 44 | +let n = 5; |
| 45 | + |
| 46 | +// upper half |
| 47 | +for (let i = 1; i <= n; i++) { |
| 48 | + let spaces = " ".repeat(n - i); |
| 49 | + let stars = "*".repeat(2 * i - 1); |
| 50 | + console.log(spaces + stars); |
| 51 | +} |
19 | 52 |
|
20 |
| -let marks = 60; |
21 |
| -if (marks >= 50) { |
22 |
| - console.log("Pass"); |
23 |
| -} else { |
24 |
| - console.log("Fail"); |
| 53 | +// lower half |
| 54 | +for (let i = n - 1; i >= 1; i--) { |
| 55 | + let spaces = " ".repeat(n - i); |
| 56 | + let stars = "*".repeat(2 * i - 1); |
| 57 | + console.log(spaces + stars); |
25 | 58 | }
|
| 59 | +``` |
| 60 | +### Output |
| 61 | +```javascript |
| 62 | + * |
| 63 | + *** |
| 64 | + ***** |
| 65 | + ******* |
| 66 | +********* |
| 67 | + ******* |
| 68 | + ***** |
| 69 | + *** |
| 70 | + * |
| 71 | + |
0 commit comments