USE JAVASCRIPT TO IMPLEMENT TO THE CODE AND REPLACE IN THIS CODE:-… USE JAVASCRIPT TO IMPLEMENT TO THE CODE AND REPLACE IN THIS CODE:- fun
USE JAVASCRIPT TO IMPLEMENT TO THE CODE AND REPLACE IN THIS CODE:-… USE JAVASCRIPT TO IMPLEMENT TO THE CODE AND REPLACE IN THIS CODE:- function toProvince(postalCode, useShortForm) { // Replace this comment with your code…} /******************************************************************************* * Problem 4: convert a valid Canadian Postal Code to a Canadian Province * * The first letter of a Postal Code tells us which province the Postal Code is * from. Here’s the list of Provinces/Territories, their 2-letter short form, * and the first letter(s) of the Postal Code that matches it: * * Province Name Short Form First Letter of Postal Code * —————————————————————————– * Ontario ON K, L, M, N, P * Quebec QC G, H, J * Nova Scotia NS B * New Brunswick NB E * Manitoba MB R * British Columbia BC V * Prince Edward Island PE C * Saskatchewan SK S * Alberta AB T * Newfoundland and Labrador NL A * Nunavut, Northwest Territories NT X * Yukon YT Y * * The toProvince() function converts a valid postal code to a province name. Use * your fixPostalCode() function from the previous problem to format and validate * the `postalCode` argument first. If it is invalid, return `null`. HINT: use try/catch * to deal with fixPostalCode() throwing an error, see: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try…catch * * If the `useShortForm` argument is `true`, the province’s short-form is * returned instead of the full name. For example: * * toProvince(‘M5W1E6’) returns ‘Ontario’ * toProvince(‘M5W 1E6’) returns ‘Ontario’ * toProvince(‘M5W 1E6’, true) returns ‘ON’ * toProvince(‘M5W’) returns null * * @param {string} postalCode – a postal code to be validated and used * @param {boolean|undefined} useShortForm – whether to return the full or short name * @returns {string} – a province name or short form ******************************************************************************/ function toProvince(postalCode, useShortForm) { // Replace this comment with your code…} Computer Science Engineering & Technology Java Programming COMPUTERS 3175 Share QuestionEmailCopy link


