Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I ensure the text stays within the container and doesn't overflow?
#2
"I've tried debugging it,"

obviously not very well
just add some console.log statements in there , like this 
and you'll see the problem

Code:
function calculateSum(arr) {
let sum = 0;
for (let i = 0; i <= arr.length; i++) {
  console.log(i + ' = ' + sum);
  sum += arr[i];
}
console.log('sum = ' + sum);
return sum;
}

const numbers = [1, 2, 3, 4, 5];
const result = calculateSum(numbers);
console.log(result); // Output should be 15, but it's not
[-] The following 1 user Likes bluebooger's post:
  • tom22
Reply


Messages In This Thread
RE: Why Does My Function Not Return the Expected Result? - by bluebooger - 08-02-2023, 06:08 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Communism doesn't work? Shocking state of $29m government-run supermarket in KC LevelUP 15 1,236 07-30-2025, 11:39 PM
Last Post: NotJoeBiden
  Family Moves to Russia to Escape Woke LGBTQ Ideology, But It Doesn't Go Very Well Jonathan Whatley 4 2,772 07-25-2024, 09:29 AM
Last Post: Charles Fout
  Text Neck Pro - FREE bjcheung77 1 1,451 12-29-2020, 05:07 PM
Last Post: SweetsugarNL
  Straighterline Text books Tasman 5 2,283 11-20-2010, 11:20 PM
Last Post: burbuja0512

Forum Jump:


Users browsing this thread: 1 Guest(s)