Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSTEAD THIS :
- function getTranslation(rhyme) {
- switch (rhyme.toLowerCase()) {
- case "apples and pears":
- return "Stairs";
- case "hampstead heath":
- return "Teeth";
- case "loaf of bread":
- return "Head";
- case "pork pies":
- return "Lies";
- case "whistle and flute":
- return "Suit";
- default:
- return "Rhyme not found";
- }
- }
- U CAN USE THIS
- function getTranslationMap(rhyme) {
- const rhymes = {
- "apples and pears": "Stairs",
- "hampstead heath": "Teeth",
- "loaf of bread": "Head",
- "pork pies": "Lies",
- "whistle and flute": "Suit",
- };
- return rhymes[rhyme.toLowerCase()] ?? "Rhyme not found";
- }
- ----------- EXAMPLE WITH FUNCTIONS INSIDE ------
- function calculate(num1, num2, action) {
- const actions = {
- add: (a, b) => a + b,
- subtract: (a, b) => a - b,
- multiply: (a, b) => a * b,
- divide: (a, b) => a / b,
- };
- return actions[action]?.(num1, num2) ?? "Calculation is not recognised";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement