Question
I need help with these last two functions in javascript, we only covered HTML so far in classes and javascript was just thrown at us:
I need help with these last two functions in javascript, we only covered HTML so far in classes and javascript was just thrown at us:
Function 8:
* A dataset contains fields that indicate a value is true or false. However,
* users have entered data in various formats and languages (English and French)
* over the years, and the data is a mess. For example, the dataset contains all
* of the following values:
*
* "True" values include: Yes, yes, YES, Y, Oui, oui, OUI, O, t, TRUE, true, True,
* vrai, V, VRAI, 1, 2, ...any positive number
*
* "False" values include: No, no, NO, Non, non, NON, N, n, f, FALSE, false, False,
* FAUX, faux, Faux, 0, -1, -2, ...any negative number
*
* Write two functions that work in similar ways: countTrue() and countFalse()
* both take any number of string, number, or boolean values and count the
* number of items that are either "true" or "false", according to the following rules:
*
* 1. If the value is already a Boolean (true or false) count it as true or false respectively
* 2. If the value is one of the "true" type values, count it as true
* 3. If the value is one of the "false" type values, count it as false
* 4. If the value is none of the "true" or "false" values, ignore it
*
* Your countTrue() and countFalse() functions will have a lot of similarities.
* Write a third function that can be re-used by countTrue() and countFalse()
* to do the common part of this operation. You shouldn't copy/paste any
* code or share much logic between countTrue() and countFalse().
Function 9:
* Querying a web data API involves formatting a query string in a particular way.
* As we know from week 1, a query string is a set of name=value pairs, that starts
* with the ? character, and each pair is separated by the & character
*
* For example:
*
* ?q=dog&sort=ascending includes q=dog and sort=ascending
* ?_encoding=UTF8&node=18521080011 includes both _encoding=UTF8 and also node=18521080011
*
* Write a buildQueryString() function to build a query string based on arguments
* passed by the caller.
*
* The buildQueryString() function accepts the following arguments:
*
* - queryTerm: a search string, for example "butterfly" or "Horse-chestnut"
* - sortOrder: a string indicating sort order, with possible values of `ascending` or `descending`
* - count: a number from 10 to 200, indicating how many results to return per page
*
* Write an implementation of buildQueryString() that accepts arguments for all of the above
* parameters, validates and formats them (e.g., encode the query, count must be between 10
* and 200, etc), and returns a properly formatted query string.
*
* For example:
*
* buildQueryString('Monarch Butterfly', 'ascending', 25) would return the following query string:
*
* '?query_term=Monarch%20Butterfly&count=25
*
* NOTE: the default sort order is ascending, so it isn't included. However, if we were to
* specify 'descending', it would need to get added:
*
* buildQueryString('Monarch Butterfly', 'descending', 25) would return the following query string:
*
* '?query_term=Monarch%20Butterfly&count=25&descending
*
* NOTE: if any of the values passed to buildQueryString() are invalid, an Error should be thrown.
*
* NOTE: make sure you properly encode the query value, since query strings can't contain
* spaces or other special characters. HINT: use the encodeURIComponent() function
* to do this, see:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started