This repository was archived by the owner on Apr 18, 2025. It is now read-only.
generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 51
NW6 | Nazanin_Saedi| Module-JS1 | WEEK4 #182
Open
nazaninsaedi
wants to merge
6
commits into
CodeYourFuture:main
Choose a base branch
from
nazaninsaedi:Exweek4NS
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
|
||
// Predict and explain first... | ||
// unction parameters should be specified by their names, | ||
// not by values or literals. So, function square(3) is not a valid function declaration. | ||
|
||
// this function should square any number but instead we're going to get an error | ||
//The syntax for declaring a function includes naming the parameters, and it should look like this: | ||
function square(num) { | ||
return num * num; | ||
} | ||
//3 is not a valid parameter name | ||
|
||
|
||
|
||
// what is happening? How can we fix it? | ||
|
||
function square(3) { | ||
return num * num; | ||
} | ||
|
||
|
||
//Now, you can call this function with a number as an argument, and it will square that number: | ||
console.log(square(5)); // Outputs: 25 |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -2,3 +2,18 @@ | |
|
||
// continue testing and implementing getOrdinalNumber for additional cases | ||
// Write your tests using Jest - remember to run your tests often for continual feedback | ||
|
||
// Assuming your getOrdinalNumber function is designed to take an integer as input and | ||
// return its ordinal representation (e.g., 1st, 2nd, 3rd, etc.), here are some test cases: | ||
// getOrdinalNumber.js | ||
|
||
/** | ||
* Function to get the ordinal representation of a number. | ||
* @param {number} n - The input number. | ||
* @returns {string} - The ordinal representation of the input number. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to finish this |
||
function getOrdinalNumber(n) { | ||
// Implementation of the function goes here | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,29 @@ | ||
// Given a positive integer num, | ||
// When the isPrime function is called with num as input, | ||
// Then it should return a boolean representing whether the num is prime | ||
|
||
//a function named isPrime that takes a parameter num. | ||
|
||
function isPrime(num) { | ||
// If the number is less than 2, it's not prime | ||
//If the input number num is less than 2, it's not a prime number, so the function returns false. | ||
if (num < 2) { | ||
return false; | ||
} | ||
//The function uses a for loop to iterate from 2 to the square root of num. | ||
// Inside the loop, it checks if num is divisible by the current value of i. | ||
// If it is divisible, the function returns false, indicating that the number is not prime. | ||
|
||
// Check for divisibility from 2 to the square root of the number | ||
for (let i = 2; i <= Math.sqrt(num); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but it is quite complicated - are you confident in your understanding? |
||
if (num % i === 0) { | ||
// If the number is divisible by any other number, it's not prime | ||
return false; | ||
} | ||
} | ||
|
||
// (If no divisor is found, the number is prime) | ||
return true; | ||
} | ||
//If the loop completes without finding any divisor, the function returns true, | ||
//indicating that the number is prime. |
This file contains hidden or 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 |
---|---|---|
|
@@ -14,3 +14,24 @@ To be valid, a password must: | |
|
||
You must breakdown this problem in order to solve it. Find one test case first and get that working | ||
*/ | ||
|
||
|
||
// Defines a function named isPasswordValid that takes a parameter password. | ||
function isPasswordValid(password) { | ||
// Step 1: Check if the password has at least 5 characters | ||
if (password.length < 5) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, need to impliment the rest |
||
return false; | ||
} | ||
//If the length of the password is less than 5, | ||
//the function returns false, indicating that the password is not valid. | ||
|
||
return true; | ||
// If the password passes all the checks, return true | ||
} | ||
// If the password passes all the checks (we only have one check for now), | ||
// the function returns true. | ||
|
||
// Test case | ||
const testPassword = "abcde"; | ||
const result = isPasswordValid(testPassword); | ||
console.log(result); // Output: false (because "abcde" has less than 5 characters) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works but is not what the question asked for I'm afraid - please read the instructions again and tweak it