Skip to the content.
3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 JS for Loops and Sprites

Big Idea 3.10 Hacks

We learned about lists and how to access elements aList[i] and append elements append().

#Hack1
aList = ['apple', 'banana', 'cherry']
aList.append('grade')

#Hack2
aList.insert('apple', 'a') 
aList.remove('kiwi')  # Removes 'kiwi' from the list
del aList[2]  # Deletes 'cherry' at index 2

#Hack3
aList[1] = 'banana'

#HomeworkHack
#l = [1, 2, 3, 4, 5, 6, 7]
l = [9, 8, 7, 4]
count = len(l)
sum = 0
for i in range(0,len(l)-1):
    if l[i] % 2 == 0:
        sum = sum + l[i]

while count != 0:
    for i in range (1, len(l)):
        if l[i-1] > l[i]:
            print(l[i-1], l[i],l)
            temp = l[i]
            l[i] = l[i-1]
            l[i-1] = temp
    count = count - 1
print("The sum of the even values is", sum)
print("List:", l, "Min:", l[0], "Max:", l[-1])