Project - Make A Library
Project - Make A Library
Project - Make A Library
Project Description
Libraries let you build functions that you and others can use to help build more powerful apps in lots of situations. As
the designer of a library you not only need to know how to program, you also need to think about the many different
kinds of programs other people might build.
For this project you will design and build a library of functions around any topic you want. You will have an opportunity
to exchange feedback with another group about how you might use their library to design an app. Finally you will
answer a few questions about the library you designed.
Library Requirements
● Your library must contain two or more functions
● At least one function must include
○ A loop
○ An if-statement
○ One or more parameters
○ Return
Step 1 - Brainstorm
Your library can be about any topic. If you need some ideas try the list below
● Strings
○ Capitalize: Capitalize first letter of each word in a sentence (long string)
○ Trim: Remove spaces from beginning and end of a string
○ Remove Letter: removes a given letter from a string
○ Anything else you'd want to do with a string
● Lists
○ Maximum: Find the maximum value in a list
○ Minimum: Find the minimum value in a list
○ Average: Find the average value in a list
○ Count: Count how many times a given value appears in a list
○ Combine: Join two lists together in one longer, larger list
○ Filter Numbers: Keep numbers in a list greater than or less than a provided value
○ Filter Letters: Keep strings in a list that begin with a given letter
○ Numbered List: Turn a list into a string with each item numbered and appearing on a different line
○ Top 3: Return the three biggest numbers in a list, in sorted order (This can be a little tricky)
○ Unique: Return a list of each unique item that appears in (This can be a little tricky)
○ Sort: Return the list in sorted order (This can be a little tricky)
○ Anything else you'd want to do with a list
● Dataset
○ Choose a dataset and build a function that will help a user access or summarize specific information
within that dataset
● Something else
○ As long as your library does something interesting and valuable
maximum(list) // Takes a list and returns the largest value Yes this function should include all of
that appears in the list these features.
// list {list} - the list of items
// return {number} - the largest number in
the list
// Randomly selects a flag from the array ● Description, Parameters, Return: Displays a
random flag from the array.
and updates the flag image element
● Loop: No.
randomize // No parameters ● If-statement: No.
// return {void} - does not return a value but ● Param: No.
updates the 'countryFlag' image element ● Return?: No (updates UI elements instead).
// Loads country data into the 'Country' and ● Description, Parameters, Return: Populates
the global variables with country names
loadCountries 'flag' arrays from a given data source
and flag URLs from a data source.
// No parameters ● Loop: Yes (to loop over the data source and
// return {void} - populates the 'Country' populate the arrays).
and 'flag' global scope arrays ● If-statement: No.
● Param: No direct parameters (assumes
access to a data source).
● Return?: No (performs an action but does
not return a value).
Step 3 - Build
Program your library. Make sure you do the following.
Step 4 - Test
Write test cases for each of the functions in your library to make sure they return the expected values. Remember that
you should include.
● Inputs (arguments) that will result in your functions behaving differently or returning different values
● Inputs (arguments) just before, at, and after cut offs if your conditionals. For example if your code includes the
statement (value < 2) then try inputs where value is 1, 2, and 3 to see if the algorithm always behaves as you
expect.
Note: Once you are done testing your functions, make sure to comment out any tests you have written into your code
to test your library functions before sending your library to a classmate in Step 5.
Yes Kind Of No
I like: Give feedback on at least one thing you like in the library
I appreciate the interactive aspect of the library that allows users to engage with the learning material through
guessing. The simple and clear structure of the functions (myFunction and randomize) makes the code easy to
understand and follow. It encourages user participation and can be a very effective way of learning about
countries and their flags.
One limitation is that the code relies on exact matches for the country names, which could be a problem if
users make minor spelling errors or if there are variations in country names (such as "USA" versus "United
States"). This could lead to unnecessary frustration for users.
What if: Give one idea for how to improve the library
To improve the library, what if we implemented a more forgiving input validation? We could include features
such as autocorrect suggestions or a fuzzy search mechanism that can handle minor spelling errors or
different valid names for the same country. Additionally, adding a hint feature that provides partial
information about the country when the user struggles to guess the correct answer could enhance the learning
experience.
Step 6 - Improve
Based on the feedback above, make final improvements to your library.
//If you have made a guess, this will state if you guess was right or wrong
onEvent("guessButton", "click", function( ) {
myFunction();
});
//If the button is pressed, it will switch the flags to another country
onEvent("randomButton", "click", function( ) {
randomize();
});
//This will randomize the country flags that will be shown on the app
function randomize() {
var index = randomNumber(0, flag.length - 1);
setProperty("countryFlag", "image", flag[index]);
}
ChatGPT // Validates the user's guessed country name with fuzzy matching
function validateGuess(guessCountry) {
// Implement fuzzy matching logic here
// This could be a simple case-insensitive match or use a more advanced library like
Fuse.js
var isMatch = fuzzyMatch(guessCountry, Country);
return isMatch;
}
The `getClosestMatches` function suggests country names similar to a user's guess by:
1. Preparing the Input: Converts the user's guess to lowercase for case-insensitive comparison.
2. Iterating Countries: Loops through a list of countries, comparing each to the user's input.
3. Selecting Matches: Identifies countries starting with the same letter as the user's input.
4. Collecting Suggestions: Adds up to three matching countries to a suggestions list.
5. Returning Suggestions: Outputs the list of suggested countries for the user.
This process involves case normalization, iteration through a list, conditional selection of matches, and managing a
collection of suggestions to be returned.
Call 1 Call 2
Conditions Checked ● The function tests if there ● The function checks for
What conditional are any country names that country names starting with
statement is checked to
make different segments
start with the rare letter "X". the common letter "C" and
of the function run tests the mechanism for
Segment of Code Executed: limiting suggestions.
Results Since "Xylophone Land" and ● The result will be the first
What will happen / be "Xanadu" both start with "X", they three countries starting with
returned by this function
call?
are added to the suggestions array. "C" from the list, which are
(outputs) However, the function limits the ["China", "Canada",
suggestions to three, which in this "Cuba"]. This demonstrates
case, is not reached, so all how the function caps
matching entries are returned. The suggestions to avoid
result is ["Xylophone Land", overwhelming the user, even
"Xanadu"]. though there are more
matching entries.
Scoring Guidelines
Selected procedure includes a parameter that impacts the functionality of the procedure /1
Response 3 Call 1: the response indicates the arguments that are passed, the specific condition that is /1
checked, and the result of the call.
Response 3 Call 2: the response indicates the arguments that are passed, the specific condition that is /1
checked, and the result of the call.
Program Code
All functions include comments that explain the purpose of the function and the parameters /2
All functions include tests that demonstrate the code working as expected /2
Project Guide
Student provided clear and actionable feedback to a classmate on their project guide /1
Total /14