Can this function work for PT since it technically is part of an onEvent?

I’m looking for a little clarification on the idea that event handlers can’t be used for the functions they analyze. This function call is housed within an event handler, but it’s not really the event handler doing the work - it’s the function being called. Can someone clarify if this is ok for use on the PT?

Screenshot 2023-02-13 134513

It is not considered a student-developed procedure and it cannot be called without an event happening.

Is there a quality example of this without an onEvent? I would love to see one on code.org. I’m new here and having trouble wrapping my head around what it’s asking kids to do in row 4.

I got this from the StateLibrary example in Unit 7 Lesson 6. This method meets all of the requirements

function stateAbbreviation(stateName){
  var allStateNames = getColumn("US States", "State Name");
  var allStateAbbreviations = getColumn("US States", "Code Name");
  for(var i=0; i<allStateNames.length; i++){
    if(allStateNames[i].toLowerCase() == stateName.toLowerCase()){
      return allStateAbbreviations[i];
    }
  }
  
  return "Not found";
}

Ok so if I understand correctly they’re just linking the wrong part - they should be screenshotting the function itself and the code it runs, not the event that calls the function and then they should be fine.

I would also like clarification on this. Examples I am seeing online, have a handler, but it is not referenced in the code in their written submission.

Yes, thats right. The picture should be the DEFINITION of the function that has all the stuff(sequencing, selection, iteration, parameter). ONLY the definition of the function should be attached. The response is asking about the function itself so the response should be about the function itself and not the overall code(which would include onEvents or other places etc where its called.)

1 Like