FAQ: Arrays - Review

This community-built FAQ covers the “Review” exercise from the lesson “Arrays”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Swift

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

what is wrong with my code? Why I am getting 81 instead of 27 for the oddSum? Thanks

var list = [2, 4, 3, 6, 1, 9]

// Write your code below :abacus:

var evenNum: Int = 0
var oddSum: Int = 1

for item in list {

if item % 2 == 0 {

 evenNum += item

} else if item % 2 == 1 {

oddSum = item * item



print(evenNum, oddSum)
print (“Sum of even numbers is (evenNum)”)
print(“Product of odd numbers is (oddSum)”)

I think the error is in oddSum = item * item, it should be oddSum = oddsum * item or more simple oddSum *= item.


I also did it this way and it works.

1 Like

var list = [2, 4, 3, 6, 1, 9]

// Write your code below :abacus:
var sum = 0
var product = 1

for item in list {
item % 2 == 0 ?
sum += item :
product *= item

print (“sum of even numbers is (sum)”)
print (“product of odd numbers is (product)”)

it turns out to be an error

EvenOdd.swift:9:15: error: result values in ‘? :’ expression have mismatching types ‘()’ and ‘Int’
sum += item :

but i just can understand what it is. so can anyone help with me please >.>
1 Like

If anyone was wondering why Codecademy used so many emojies in this course, it is because in Swift 5.3 variable names can be anything, even unicode caharcters!


You are getting the error because of the statement
item % 2 == 0 ? sum += item : product *= item

If you change it to
item % 2 == 0 ? (sum += item) : (product *= item)
it will work.

Have a look at

var list = [2, 4, 3, 6, 1, 9]

// Write your code below :abacus:

var even = 0
var odd = 1

for num in list {
num % 2 == 0 ? (even += num) : (odd *= num)

print(“Sum of even numbers is: (even)”)
print(“Product of odd numbers is: (odd)”)