Debugging - Exercise 1

Question 1: Fix a Numeric String Sum

Fix the function so it converts the numeric text before adding it to the number.

Expected output: 15 (print this with console.log)

javascript

function debugNumericTextSum(number, text) {
  return number + text;
}

console.log(debugNumericTextSum(7, "8"));

Question 2: Fix an Inclusive Minimum

Fix the comparison so values equal to the minimum also pass.

Expected output: true (print this with console.log)

javascript

function debugInclusiveMinimum(value, minimum) {
  return value > minimum;
}

console.log(debugInclusiveMinimum(5, 5));

Question 3: Fix a Last Array Item

Fix the index so the function returns the final item of a non-empty array.

Expected output: "b" (print this with console.log)

javascript

function debugLastArrayItem(items) {
  return items[items.length];
}

console.log(debugLastArrayItem(["a","b"]));

Question 4: Fix a Rectangle Area

Fix the arithmetic so the function returns rectangle area.

Expected output: 15 (print this with console.log)

javascript

function debugRectangleArea(width, height) {
  return width + height;
}

console.log(debugRectangleArea(3, 5));

Question 5: Fix a Fahrenheit Conversion

Fix the formula for converting Celsius to Fahrenheit.

Expected output: 32 (print this with console.log)

javascript

function debugFahrenheitConversion(celsius) {
  return celsius * 5 / 9 + 32;
}

console.log(debugFahrenheitConversion(0));

Question 6: Fix an Assignment in a Condition

Fix the condition so it compares the supplied status with "ready" instead of changing it.

Expected output: false (print this with console.log)

javascript

function debugStatusComparison(status) {
  return (status = "ready") === "ready";
}

console.log(debugStatusComparison("waiting"));

Question 7: Fix Strict Code Comparison

Fix the comparison so values with different types are not considered equal.

Expected output: false (print this with console.log)

javascript

function debugStrictCodeComparison(first, second) {
  return first == second;
}

console.log(debugStrictCodeComparison(5, "5"));

Question 8: Fix a Default for Zero

Fix the function so it uses 10 only for null or undefined and preserves zero.

Expected output: 0 (print this with console.log)

javascript

function debugNullishDefault(value) {
  return value || 10;
}

console.log(debugNullishDefault(0));

Question 9: Fix a Returned Object

Fix the arrow function so it returns an object with a value property.

Expected output: {"value":3} (print this with console.log)

javascript

function debugArrowObjectReturn(input) {
  const make = (value) => { value: value };
  return make(input);
}

console.log(debugArrowObjectReturn(3));

Question 10: Fix a Boolean Toggle

Fix the function so it returns the opposite of the supplied boolean.

Expected output: false (print this with console.log)

javascript

function debugBooleanToggle(enabled) {
  return enabled;
}

console.log(debugBooleanToggle(true));