JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 8 5 Exercise 1

		
001window.onload = ()=>{
		
002	
		
003	const student = {
		
004		forename: 'John',
		
005		surname: 'James',
		
006		age: 32
		
007	}
		
008	// create variable to hold the output
		
009	let str = 'Student: \n'; // \n is a new line in the console 
		
010	
		
011	for(const studentData in student)
		
012	{
		
013		str += capitaliseString(studentData) + ': ' + student[studentData]+ '\n';
		
014	}
		
015	console.log(str);	
		
016	
		
017	
		
018	
		
019	function capitaliseString(str)
		
020	{
		
021		str = str.toLowerCase();
		
022		str = str[0].toUpperCase() + str.slice(1);
		
023		return str;
		
024	}
		
025}