I get stuck in day 9, task 4.
-
- Add another test script : Still under the Tests tab of the
get starships
request, add code to loop through the starships and determine which starship is the fastest.
- Add another test script : Still under the Tests tab of the
- Initialize two collection variables called
fastestShip
andfastestSpeed
. The INITIAL values can be your first name and0
. - You must cast a string to a number to compare numerical values, like speed.
- Keep track of the fastest starshipās
name
andmax_atmosphering_speed
as collection variables, to use in the next step.
I added test script
var response = pm.response.json();
var starships = response.results;
var fastestShip = pm.collectionVariables.get("fastestShip");
var fastestSpeed = parseFloat(pm.collectionVariables.get("fastestSpeed"));
for (var i = 0; i < starships.length; i++) {
var speed = parseFloat(starships[i].max_atmosphering_speed);
if (speed > fastestSpeed) {
fastestSpeed = speed;
fastestShip = starships[i].name;
}
}
pm.collectionVariables.set("fastestShip", fastestShip);
pm.collectionVariables.set("fastestSpeed", fastestSpeed.toString());
But error There was an error in evaluating the test script: TypeError: Cannot read properties of undefined (reading ālengthā)
Could you give me a hint How I can solve it?