0% found this document useful (0 votes)
3 views1 page

Corrected Code Explanation Table

The document provides a corrected code explanation in a table format, detailing the functionality of a program that prints certain odd numbers from an array. It describes the start of the program, the creation of an array, and the logic within the 'onlyOdds' function to check and print odd numbers. The document concludes with a summary message indicating that all odd numbers have been printed.

Uploaded by

stairscaiden
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Corrected Code Explanation Table

The document provides a corrected code explanation in a table format, detailing the functionality of a program that prints certain odd numbers from an array. It describes the start of the program, the creation of an array, and the logic within the 'onlyOdds' function to check and print odd numbers. The document concludes with a summary message indicating that all odd numbers have been printed.

Uploaded by

stairscaiden
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Corrected Code Explanation (Table Format)

Code Explanation

function start() { Begins the program.

println("1"); Prints 1.

var arr = [1, 2, 3, 5, 6, 7]; Creates an array of numbers.

var odds = onlyOdds(arr); Calls onlyOdds and passes the array.

} Ends the function.

function onlyOdds(arr) { Starts the onlyOdds function.

oddNum = arr[2] % 2 Checks the 3rd element (3) for odd/even.

oddNumTwo = arr[4] % 2 Checks the 5th element (6).

oddNumThree = arr[5] % 2 Checks the 6th element (7).

if (oddNum == 1) { println("3"); } Prints 3 because it is odd.

if (oddNumTwo == 1) { println("6"); } Does not print because 6 is even.

if (oddNumThree == 1) { println("7"); } Prints 7 because it is odd.

println("All odd numbers have been Displays a summary message.


printed.");

} Ends the function.

You might also like