-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yashcoderabbit
committed
May 29, 2025
1 parent
aeb4b22
commit 754b4ae
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * A comprehensive greeting library with intentional bugs | ||
| */ | ||
|
|
||
| // This variable will be used without initialization (BUG) | ||
| let defaultTitle = { type: "guest" }; | ||
| /** | ||
| * Prints a greeting to the console. | ||
| * @param {string} name | ||
| */ | ||
| export function greet(name) { | ||
| console.log(`Hello, ${name}!`); | ||
| // BUG: Accessing property of undefined | ||
| console.log(`Your title is ${defaultTitle.type}`); | ||
| } | ||
|
|
||
| /** | ||
| * Prints a welcome message to the console. | ||
| * @param {string} name | ||
| */ | ||
| export function welcome(name) { | ||
| console.log(`Welcome back, ${name}!!`); | ||
| // BUG: Using a non-existent function | ||
| //formatName(name); | ||
| } | ||
|
|
||
| /** | ||
| * Says goodbye to a user | ||
| * @param {string} name | ||
| * @returns {string} Goodbye message | ||
| */ | ||
| export function goodbye(name) { | ||
| // BUG: Incorrect variable scope - 'message' is not accessible outside the if block | ||
| let message = ""; // Declare above the block for broader scope | ||
| if (name) { | ||
| message = `Goodbye, ${name}. See you soon!`; | ||
| } | ||
| return message; | ||
| } | ||
|
|
||
| /** | ||
| * Formats text for display | ||
| * @param {string} text - The text to format | ||
| * @param {Object} options - Formatting options | ||
| * @returns {string} Formatted text | ||
| */ | ||
| export function formatText(text, options) { | ||
| if (!text) return ''; | ||
| if (!options) options = {}; | ||
|
|
||
| if (options.makeUpper) { | ||
| const formattedText = text.toUpperCase(); | ||
| return formattedText; | ||
| } else if (options.makeLower) { | ||
| return text.toLowerCase(); | ||
| } else { | ||
| return text; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns time-based greeting | ||
| * @param {string} name - User's name | ||
| * @returns {string} Time-appropriate greeting | ||
| */ | ||
| export function timeGreeting(name) { | ||
| const hour = new Date().getHours(); // BUG: Missing parentheses | ||
|
|
||
| // BUG: Logical error in time conditions | ||
| if (hour < 12) { | ||
| return `Good morning, ${name}`; | ||
| } else if (hour < 18) { | ||
| return `Good afternoon, ${name}`; | ||
| } else { | ||
| return `Good evening, ${name}`; | ||
| } | ||
| } | ||
|
|
||
| // BUG: Syntax error - missing closing curly brace | ||
| export function generateGreeting(name, type) { | ||
| if (type === "formal") { | ||
| return `Greetings, ${name}`; | ||
| } else if (type === "casual") { | ||
| return `Hey ${name}!`; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Capitalizes a name | ||
| * @param {string} name | ||
| * @returns {string} | ||
| */ |