Skip to content

Angelika S - #9

Open
angelika-arch wants to merge 1 commit into
HackYourAssignment:mainfrom
angelika-arch:main
Open

angelika-arch wants to merge 1 commit into
HackYourAssignment:mainfrom
angelika-arch:main

Conversation

@angelika-arch

Copy link
Copy Markdown

No description provided.

@angelika-arch angelika-arch changed the title Week 3 JS assigments Angelika S Nov 18, 2026
Comment thread task-1/book.js
function isBookApplicable(searchString) {
// Your code here
const title = "The fundamentals of JavaScript";
const normalizedSearch = searchString.trim().toLowerCase();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor indentation here, probably by accident since the rest of your code is properly intended.

important to think of 3 audiences for your code:

  • the computer
  • other developers
  • yourself in the future (in a few months you'll forget what you wrote here)

indentation signals scope (to the reader) in most programming languages.

python uses indentation (and nothing else) to define scope as part of the language itself

not a big deal here, but it can be a big deal if you don't notice it

Comment thread task-2/parse-date.js
const first = Number(numbers[0]);
const second = Number(numbers[1]);
const year = Number(numbers[2]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the section above has 6 lines of code doing things which are not documented anywhere (comments would be OK, better would be clearer code, see example below)

// parse incoming string: "MDY ##-##-####" or "DMY ##-##-####"
const parts = dateString.split(" ");
const format = parts[0];  // format is either "MDY" or "DMY"
const numbers = parts[1].split("-");  

const first = Number(numbers[0]);
const second = Number(numbers[1]);
const year = Number(numbers[2]);

minor adjustment

const first = Number(numbers[0]);
const second = Number(numbers[1]);
const year = Number(numbers[2]);

can we rewritten as ... (this is called "destructuring the array")

const [first, second, year] = date.split("-")

alternative, shorter, a little cleaner.

here the .map() function is used to convert each string to a number using the Number() constructor (see examples here).

// parse incoming string
const [format, date] = dateString.split(" ") // prefix MDY or DMY followed by space
const [first, second, year] = date.split("-").map(Number) // year is always last

Comment thread task-2/parse-date.js

if (format === "MDY") {
return { day: second, month: first, year: year };
}

@amgando amgando Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you're missing the alternative case of "DMY" as format string

imagine if someone passes any other string prefix

all of the following would work with the current version of your code but would fail in surprising ways

parseDateString("DMM 10-21-1983")
parseDateString("DDD 10-21-1983")
parseDateString("hi-there 10-21-1983")

so generally speaking you need:

  1. complete coverage of all cases
  2. a default (else) case to catch everything else

a better version of this section of the code would be:

if (format === "MDY") {
  return ({ day: second, month: first, year });

} else if (format === "DMY") {
  return ({ day: first, month: second, year });

} else {
  throw new Error('Invalid format prefix') // or something like this

}

you can also do this with a switch case statement

let result = {}
result.year = year;

switch (format) {
  case 'MDY':
    result.day = second
    result.month = first
    break;

  case 'DMY':
    result.day = first
    result.month = second
    break;

  default:
    throw new Error(`Invalid format prefix: ${format}`)
}

return result;

@amgando amgando Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

on second thought, a regex ("regular expression") is a good fix for some of the issues you can find here where you try to match the regex and, if it fails, you throw an error.

this way you don't run into problems with parsing the string if it has multiple spaces or only MM-DD and missing YYYY etc.

const correctFormat = /^(MDY|DMY) (\d{1,2})-(\d{1,2})-(\d{4})$/

see here: https://regex101.com but be careful, regex is a big topic with small and rare usage. it's something that you use maybe once every year or two for very specific reasons like this one where you want to control for a very specific format in a piece of text.

image

Comment thread task-2/parse-date.js
return { day: second, month: first, year: year };
}

return { day: first, month: second, year: year };

@amgando amgando Nov 20, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

modern javascript allows you to simplify this if attribute name and value are the same. notice below I replaced year: year with just year

also make sure you surround any return value that can span multiple lines, like an object literal, with () to make sure it's returned as a single value. Without this, the risk is a line break right after return will break your code.

return ({ day: first, month: second, year});

Comment thread task-3/date.js
@@ -0,0 +1,23 @@
export function convertHoursToMinutes(hours) {
return hours * 60;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

only comment here is to replace these magic numbers with constants like MINUTES_PER_HOUR

you can have a list of constants at the top of the file

const MINUTES_PER_HOUR = 60

so the function becomes

export function convertHoursToMinutes(hours) {
  return hours * MINUTES_PER_HOUR;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same for others of course

Comment thread task-4/cleanup.js
console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C"); No newline at end of file
printWindChill("Amsterdam", 22, 15);
printWindChill("Berlin", 15, 20);
printWindChill("Copenhagen", -5, 25); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

overall this one is very good, nice work

@amgando

amgando commented Nov 20, 2026

Copy link
Copy Markdown

hi @angelika-arch,

generally speaking, solid work, well done

a few comments for you to review, let me know if you have any questions

@amgando amgando left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

generally solid work, well done

consider a few of the ideas i mentioned here and check out the links

there are 100 ways to solve any single problem. think of coding as art AND science

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