function maxNum(arr) {
let max = 0
for (let i = 0; i < arr.length; i++){
if (arr[i] > max ) {
max = arr[i]
}
}
return max
function greetAliens(aliens) {
let greeting = []
for (let i = 0; i < aliens.length; i++) {
greeting.push("Greetings " + aliens[i]);
}
return greeting
}
console.log(greetAliens(["SpaceKing", "Wegord", "Klingon", "Blorgous", "Vulcan"]));
Write a function that takes an array of numbers and adds 10 to every element of the array using the forEach( ) method and returns a new array.
const anotherArr = [ 12, 11, 12, 13, 14 ]
let addToArr = []
anotherArr.forEach(num => {
addToArr.push(num + 10)
})
console.log(addToArr)
//Logs [ 22, 21, 22, 23, 24 ]
const wordReverse = (string) => {
return string.split("").reverse().join("")
}
console.log(wordReverse("This is how we do it."))
//.split creates an array=['T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'h', 'o', 'w', ' ', 'w', 'e', ' ', 'd', 'o', ' ', 'i', 't', '.']
//.reverse simply reversese the array
//.join puts the elements of the string back together in a string
const items = ["rock", "paper", "scissors"]
function game(userInput) {
let computerInput = items[Math.floor(Math.random() * items.length)]
console.log(computerInput)
if (computerInput === userInput) {
return "This is a tie"
} else if (computerInput === "rock") {
//wrapping div
const wrapper = document.createElement("div")
document.body.appendChild(wrapper);
wrapper.style.display = "flex"
wrapper.style.alignItems = "center"
wrapper.style.justifyContent = "center"
wrapper.style.width ="100%"