Using a forEach: Would this satisify the looping through the list requirement

I have a student who used forEach. to look through a list they created. They asked if this is acceptable and I honestly do not know, better to ask than assume. Any feedback would be appreciated.

This is function he is calling:

Hi Jeff,

I think I need a little clarity on what it is you’re looking for here. If this is a project that a student is currently working on for the AP, then we cannot give any guidance about how they should implement any portion of the create task. In that case, the best I would do is remind them that they are going to write about this code. Have them perform a gut check - do they feel confident explaining this in the written portion? If so, carry. on. If no, consider other options.

If that’s maybe not your question, let me know and I’ll try to add a better response!

1 Like

There is 0 code written yet, they were asking for clarification on the rubric and rules. As I don’t know if a forEach call would work under how it is written in the rubric or if it would count.

Theoretically it should count, forEach is a prototype method used in arrays to iterate through elements in the list / array for example

var array = [1, 2, 3, 4, 5, 6];
// forEach outputs the same as a basic iterator
array.forEach(function(element) {
console.log(element);
});
// I'd assume something would count toward the rubrick
for(var i = 0; i < array.length; i++) {
var element = array[i];
console.log(element);
}

In my opinion the only way i could see this being disqualified is if you needed the current index within the iterator since this is a comparison throughout the list, other than that I’d consider it a loop just like while(){ } do { } while() or for loops I’d also imagine in this situation that forEach also looks much more readable than the basic iterator indicating that something is being searched for, not changed

hope this helps
Best, Varrience

1 Like

Thank you, that was my line of thought.

Hi @jeff.rhodes,

If this is for the Create PT, I would caution you that you are not allowed to tell the student whether you feel the forEach would count. You can certainly ask them if they think it should count, but providing guidance of any kind is strictly not allowed.

–Michael K.

Under section “Completing the Performance Task” on page 201 of the “AP Computer Science Principles - COURSE AND EXAM DESCRIPTION”, it says (addressing the student,)

“[you may] Seek clarification from your teacher or AP Coordinator on the prompts and submission requirements for the performance task when you do not understand the directions.”

To me, the question of the student about the .forEach in this post is a clarification question, and thus it is permissible to answer.