JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 3 Exercise 1

		
001let names = ["John", "Peter", "Jim"];
		
002
		
003names = names.map(
		
004		function(name)
		
005		{
		
006			return 'Mr '+name;
		
007		}
		
008);
		
009
		
010		
		
011names = names.map(
		
012		name =>
		
013		{
		
014			return 'Mr '+name;
		
015		}
		
016);		
		
017
		
018console.log(names.toString());
		
019
		
020let nums = [1,2,3,4,5,6,7,8,9,10];
		
021
		
022let oddNums = nums.filter(num => (num%2!=0));
		
023
		
024console.log(oddNums.toString());
		
025
		
026
		
027let pounds = [40, 32, 55];
		
028
		
029let total = pounds.reduce(
		
030  (prev, curr) => 
		
031		prev + curr
		
032);
		
033
		
034console.log(total);
		
035	
		
036// loop method to get total 
		
037let loopTotal = 0;
		
038for(let i =0; i<pounds.length;i++)
		
039	loopTotal += pounds[i];
		
040
		
041console.log(loopTotal);
		
042