Created
April 29, 2020 13:16
-
-
Save amandabot/fac39e797b3a8c2fc4321dc99b6a259e to your computer and use it in GitHub Desktop.
Displays a motivation meter in the console based on inputs for level, maximum level, and unit types
This file contains hidden or 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
function displayMotivation(currentLevel, maxLevel, title, unitValue, emptyValue){ | |
const negativeMotivationLevel = currentLevel < 0 ? Math.abs(currentLevel) : 0; | |
const negativeMotivation = new Array(negativeMotivationLevel).fill(unitValue || '#'); | |
const excessMotivationLevel = currentLevel > maxLevel ? currentLevel - maxLevel : 0; | |
const excessMotivation = new Array(excessMotivationLevel).fill(unitValue || '#'); | |
const motivationLevel = Math.max(currentLevel - negativeMotivationLevel - excessMotivationLevel, 0); | |
const motivation = new Array(maxLevel) | |
.fill(unitValue || '#', 0, motivationLevel) | |
.fill(emptyValue || '-', motivationLevel, maxLevel); | |
console.log(`Current ${title} Level:`); | |
console.log(`${negativeMotivation.join('')}[${motivation.join('')}]${excessMotivation.join('')}`); | |
} | |
function reportLevels() { | |
[ | |
{ | |
title: 'Saltiness', | |
level: 7, | |
maxLevel: 10, | |
unitValue: '🌶️', | |
emptyValue: '-' | |
}, | |
{ | |
title: 'Motivation', | |
level: 1, | |
maxLevel: 10, | |
unitValue: '#', | |
emptyValue: '-' | |
} | |
] | |
.forEach(scale => displayMotivation(scale.level, scale.maxLevel, scale.title, scale.unitValue, scale.emptyValue)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment