Skip to content

Conversation

@dannyelcf
Copy link
Owner

No description provided.

Comment on lines +4 to +7
SPACE,
TEMPERATURE_INPUT,
CONVERT_TEMPERATURE_CONTAINER,
MESSAGE_ERROR_NOT_INTEGER,
Copy link
Owner Author

Choose a reason for hiding this comment

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

In this file, only the TEMPERATURE_INPUT is being used. You can remove the others.

Suggested change
SPACE,
TEMPERATURE_INPUT,
CONVERT_TEMPERATURE_CONTAINER,
MESSAGE_ERROR_NOT_INTEGER,
TEMPERATURE_INPUT,


export const convertedTemperature = (fahrenheitTextList) => {
if (!/^[0-9\s]*$/.test(fahrenheitTextList)) {
window.alert(MESSAGE_ERROR_NOT_INTEGER);
Copy link
Owner Author

Choose a reason for hiding this comment

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

You defined MESSAGE_ERROR_NOT_INTEGER constant as The '%S' contains values different of integer numbers.

So, in the window.alert you must replace the %S by fahrenheitTextList content. For example:

window.alert(MESSAGE_ERROR_NOT_INTEGER.replace('%S', fahrenheitTextList));


// Validate it
if (fahrenheitTextList) {
var convertedTempTextList = convertedTemperature(fahrenheitTextList);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Don't use var. It is not recommeded anymore. Use let or const.

Suggested change
var convertedTempTextList = convertedTemperature(fahrenheitTextList);
const convertedTempTextList = convertedTemperature(fahrenheitTextList);

Comment on lines +15 to +21
var convertedTemperatures = '';
fahrenheitList.forEach((fahrenheit) => {
// Do the math
const celsius = ((fahrenheit - 32) * 5) / 9;

convertedTemperatures = convertedTemperatures + ' ' + celsius.toFixed(2);
});
Copy link
Owner Author

@dannyelcf dannyelcf May 7, 2024

Choose a reason for hiding this comment

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

Don't use var. It is not recommeded anymore. Use let or const.

Tip: use map and join functions. This will avoid the empty space at the beginning of the returned convertedTemperatures.

Suggested change
var convertedTemperatures = '';
fahrenheitList.forEach((fahrenheit) => {
// Do the math
const celsius = ((fahrenheit - 32) * 5) / 9;
convertedTemperatures = convertedTemperatures + ' ' + celsius.toFixed(2);
});
const convertedTemperatures = fahrenheitList.map((fahrenheit) => {
const celsius = ((fahrenheit - 32) * 5) / 9;
return celsius.toFixed(2);
}).join(' ');

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.

3 participants