Skip to content

NW-ITP |Mohammed Alzaki | Module-Structuring-and-Testing-Data| Sprint2 | week4 #390

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
13 changes: 11 additions & 2 deletions Sprint-2/1-key-errors/0.js
Copy link

Choose a reason for hiding this comment

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

This works fine

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

function capitalise(str) {
/* function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
} */

// =============> write your explanation here
// An error occured => SyntaxError: Identifier 'str' has already been declared
//because in javascript we cant declare a variable more than once within scope .

// =============> write your new code here
function capitalise(str) {
str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}

console.log(capitalise("cool"))
17 changes: 15 additions & 2 deletions Sprint-2/1-key-errors/1.js
Copy link

Choose a reason for hiding this comment

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

this works fine

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@
// =============> write your prediction here

// Try playing computer with the example to work out what is going on

/*
function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);
console.log(decimalNumber); */

// =============> write your explanation here
//The function convertToPercentage(decimalNumber) accepts a parameter decimalNumber
//Inside the function, ywe have decimalNumber redeclared using const decimalNumber = 0.5;, which creates a conflict
// Finally, correct the code to fix the problem
//we should remove the redeclaration of decimalNumber inside the function. Instead, use the parameter directly.and then
//pass a decimal number as input => 0.5 in the function call

// Finally, correct the code to fix the problem
// =============> write your new code here

function convertToPercentage(decimalNumber) {
const percentage = `${decimalNumber * 100}%`;
return percentage;
}

const result = convertToPercentage(0.5);
console.log(result); // Output => "50%"