Salt's Tech Journal

2025.02.18

Completed the Gradebook App exercise on freeCodeCamp. It's worth noting that I used an if else statement when a much conciser alternative was available:

function hasPassingGrade(score) {
return getGrade(score) !== "F";
}

In other news, I might like ChatGPT's color scheme too much.

2025.02.17

I decided to work with ChatGPT to see how well it could handle pseudocode (or, from a different perspective, to see how interpretable my pseudocode was). I provided the following prompt:

I have a set of test scores and need to write a function that will find the average of any set of test scores. Please write a function, called "getAverage", that can take an arbitrary number of scores, contained in a single array, and find the average score.

The function must fit the following pseudocode:

  1. Inside the function getAverage, let totalScores = array.length
  2. Let sum = 0.
  3. Add the first item in the array to sum.
  4. Remove the first item in the array.
  5. Check the length of the array.
  6. If array length > 0, return to step 4.
  7. Else, let averageScore = sum / totalScores
  8. Return as the result of getAverage

ChatGPT returned the following:

function getAverage(array) {
let totalScores = array.length; // Step 1
let sum = 0; // Step 2

// Step 3-6: Loop through the array, adding the first item to sum and removing it
while (array.length > 0) {
sum += array[0]; // Add the first item to sum
array.shift(); // Remove the first item in the array
}

// Step 7: Calculate the average score
let averageScore = sum / totalScores;

// Step 8: Return the result
return averageScore;
}

// Example usage:
let testScores = [90, 80, 70, 85, 95];
console.log(getAverage(testScores)); // Output: 84

I'll pick this apart later. If I'm going to use ChatGPT, I want to make sure that it gives me code that I don't understand (or at least code that I do not go on to understand), and also it did not take exactly the same approach that I would have taken, and I want to understand why. For now, though, it's late, and I need to do a few other things before I go to bed.