Our task: add 5 to each item in an array.
Pseudocode:
//iterate through the array
//add 5 to each item
Actual code:
//iterate through the array
for (var i = 0; i < arr.length; i++) {
//add 5 to each item
arr[i] += 5;
}
Create a function, checkStore, that searches through our bookStore array for a user-inputted book
Pseudocode:
//declare a function that takes a bookname string as a parameter
//iterate through the bookStore array
//find the title of each book
//check if the title matches the bookname
//if so, pop up alert box with title, author, and price
//ask the user if they want to add the item to their cart
//if the user selects yes, add to their cart
//if the book isn't found, alert the user that we don't have it
You'll notice that each line of pseudocode gives us clear instructions for a task we can do.
Do we follow the guidelines?
All the time.
It's super valuable.
create a function that multiplies every even number in an input array by 10 and returns the modified array
//declare a function that takes an array as a parameter
//iterate through that array
//check to see if each item is even
//if so, overwrite the array at that position with that item multiplied by 10
//return the array
Let's "invoke" this with the array [1,2,3,4]
This helps you spot bugs before you even write code!
create a function that multiplies every even number in an input array by 10 and returns the modified array
//declare a function that takes an array as a parameter
//iterate through that array
//check to see if each item is even
//if so, overwrite the array at that position with that item multiplied by 10
//return the array
Let's "invoke" this with the array [1,2,3,4]
This helps you spot bugs before you even write code!
These exercises are a review from last week and are not necessarily tied to today's lecture material (though you should always use pseudocoding to solve problems!)
https://github.com/TelegraphPrep/week2