Which debugging technique would best help test all discount code paths quickly?
function calculateDiscount(price, discountCode) {
let discount = 0;
if (discountCode === 'SUMMER20') {
discount = 0.2;
} else if (discountCode === 'SALE15') {
discount = 0.15;
} else if (discountCode === 'MEMBER10') {
discount = 0.1;
} else {
discount = 0;
}
return price - (price * discount);
}
Live variable manipulation during debugging is most efficient here: 1) By setting a single breakpoint early in the function and using the console to modify the discountCode variable, 2) You can test all code paths in a single debugging session without restarting the function, 3) After pausing at the breakpoint, you can type discountCode = 'SUMMER20' in the console to change the value, 4) Then continue execution to see the result, and repeat for other codes, 5) This interactive testing is much faster than adding console.log statements or setting multiple breakpoints, 6) You can observe the full execution flow and final return value for each code path, 7) Variables can be modified even if they were passed as parameters, 8) This technique is particularly valuable for testing multiple conditions or branches without modifying the original code.