Using LLMs for efficient learning
Content
Ideas:
Write a function that takes a comma separated string and makes it a readable sentence. For example:
convertToReadableString('hello,this,is,a,difficult,to,read,sentence'; // returns 'hello this is a difficult to read sentence'
Sometimes we want to indicate to the user what email address we are sending an email to but not fully show the address. For example, when our system works with usernames and the user requests a new password. Write a function that hides most of the email address with asterisks (*). For example:
hideEmailAddress('[email protected]') // returns j***@doe.com
hideEmailAddress('[email protected]') // returns s******@protonmail.com
<aside> 💡
Hint: you will need to use a String function that we haven’t discussed yet. Look up indexOf
</aside>
Create a function called updateScore that takes a player name and points to add. The function should update a global score variable and display the current score. Then, create another function resetGame that resets the score back to zero.
let score = 0;
function updateScore(playerName, points) {
// Your code here
// Update the score and log: "PlayerName scored X points! Total score: Y"
}
function resetGame() {
// Your code here
// Reset score to 0 and log: "Game reset! Score is now 0"
}
// Test your functions
updateScore('Alice', 10);
updateScore('Bob', 5);
resetGame();
updateScore('Charlie', 8);
Questions to consider:
score variable?let score = 0; inside the updateScore function instead?updateScore and accessing it from resetGame. What happens and why?<aside> 💡
If you would like to practice more then remember that you can ask AI to generate more exercises for you!
</aside>
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **
