Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VoiceAssistent execise #119

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Aymanngu
Copy link
Collaborator

@Aymanngu Aymanngu commented Dec 5, 2024

No description provided.

Copy link

@jmf-umbraco jmf-umbraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job overall. Tidy code and some clever ways of solving the various tasks.

I've left a few small suggestions you may want to follow-up on to make the code a little more robust or readable!


// Todos Part
if (command.startsWith("Add") && command.endsWith("to my todo")) {
const task = command.replace("Add ", "").replace(" to my todo", "");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the thing that the user wants to add to their todo list includes the text "Add "?

if (command.startsWith("Remove") && command.endsWith("from my todo")) {
const task = command.replace("Remove ", "").replace(" from my todo", "");
const index = todos.indexOf(task);
if (index > -1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good edge case handling!

if (command === "What day is today?") {
const today = new Date();
const day = today.getDate();
const month = today.toLocaleString("en-US", { month: "long" });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of .toLocaleString(), but we might be able to save ourselves some further effort by using it for the day and year as well!

Also, for real apps we should consider whether en-US is the correct choice of culture. If the rest of your app is in English, then perhaps just en without a country code is preferable. If your app is localised such that users see their native language anywhere, then we might want to use default so that the date doesn't appear in English!

num2 = parseFloat(num2);

if (isNaN(num1) || isNaN(num2)) {
return "I couldn't understand the numbers.";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an error message that gives the user more clues about how they should proceed. For example, you could help the user understand how they should be formatted, or let them know that perhaps they're missing some whitespace between the numbers and operators.


function getReply(command) {
// Name Part
if (command.startsWith("Hello my name is")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user types the command in all lower case? Would be nice if our code just handled such a situation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants