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
const getHttpStatusCode = statusCode => clientResponseCodeMap.get(statusCode) ?? clientResponseCodeMap.get(500); |
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
// Object | |
const clientResponseCode = { | |
400: 'Bad Request: The server could not understand the request due to invalid syntax.', | |
401: 'Unauthorized: The client is unauthenticated and must be properly authenticated.', | |
403: 'Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.', | |
404: 'Not Found: The server can not find the requested resource.', | |
500: 'Internal Server Error: The server has encountered a situation it does not know how to handle.', | |
}; | |
// Map | |
const clientResponseCodeMap = new Map([ |
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
// Status Code Table | |
const clientResponseCode = { | |
400: 'Bad Request: The server could not understand the request due to invalid syntax.', | |
401: 'Unauthorized: The client is unauthenticated and must be properly authenticated.', | |
403: 'Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.', | |
404: 'Not Found: The server can not find the requested resource.', | |
500: 'Internal Server Error: The server has encountered a situation it does not know how to handle.', | |
}; | |
// getHttpStatusCode function that returns the message response associated with that status code. |
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
// Client Response Code Object | |
const clientResponseCode = { | |
400: 'Bad Request: The server could not understand the request due to invalid syntax.', | |
401: 'Unauthorized: The client is unauthenticated and must be properly authenticated.', | |
403: 'Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.', | |
404: 'Not Found: The server can not find the requested resource.', | |
500: 'Internal Server Error: The server has encountered a situation it does not know how to handle.', | |
}; |
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
// Switch Statement: Client Response Codes | |
switch (httpStatusCode) { | |
case 400: | |
statusCodeResponse = `${httpStatusCode} Bad Request: The server could not understand the request due to invalid syntax.`; | |
break; | |
case 401: | |
statusCodeResponse = `${httpStatusCode} Unauthorized: The client is unauthenticated and must be properly authenticated.`; | |
break; | |
case 403: | |
statusCodeResponse = `${httpStatusCode} Forbidden: The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource.`; |
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
let lightColor = 'Green'; | |
switch (lightColor) { | |
case 'Red': | |
console.log('Stop'); | |
break; | |
case 'Yellow': | |
console.log('Slow'); | |
break; | |
case 'Green': | |
console.log('Go'); |
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
if (num % 15 === 0) { | |
console.log('FizzBuzz'); | |
} else if (num % 3 === 0) { | |
console.log('Fizz'); | |
} else if (num % 5 === 0) { | |
console.log('Buzz'); | |
} else { | |
console.log(num); | |
} |
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
if (num % 2 === 0) { | |
console.log('TRUE'); | |
} | |
console.log('FALSE'); |
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
const nums = [1,2,3,4,5]; | |
const isEven = num => { | |
if(num % 2 === 0) return num; | |
}; | |
const isOdd = num => { | |
if(num & 2 !== 0) return num; | |
} |
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
const sampleObject = { | |
author: "J.R.R. Tolkien", | |
genre: "Sci-Fi/Fantasy", | |
birthday: "January 3, 1892", | |
books: [ | |
{ | |
title: "The Silmarillion", | |
publicationDate: 1927 | |
}, | |
{ |
NewerOlder