diff --git a/bryantferguson/src/js-data-types-lab/lab.js b/bryantferguson/src/js-data-types-lab/lab.js new file mode 100644 index 0000000..af80584 --- /dev/null +++ b/bryantferguson/src/js-data-types-lab/lab.js @@ -0,0 +1,147 @@ +// Practice 1 +let fullName = "Bryant Ferguson" +console.log(fullName.length); +console.log(fullName.toUpperCase()); +console.log(fullName.includes("Ferguson")); +let firstName = fullName.split(" "); +console.log(firstName[0]); + +// Practice 1 Mini Challenge +function helloName(name) { + return "Hello, " + name + "!"; +} + +helloName("Bryant"); + +// .length gets the length of string or an array +// .includes() returns a boolean on whether a certain value is in a string +// .slice() returns a portion of a string based on the substring range + +// Practice 2 + +let num1 = 10; +let num2 = 3; + +console.log(num1 + num2); // addition +console.log(num1 - num2 ); // subtraction +console.log(num1 * num2); // multiplication +console.log(num1 / num2 ); // division +console.log(num1 % num2); // remainder +let num = Math.floor(Math.random() * 10) + 1; +console.log("random num " + num); + +function evenOrOdd(number){ + if(number % 2 == 0){ + return true; + } + return false; +} + +console.log(evenOrOdd(11)); + +//% is the remainder after the dvision +//math random returns a random number based on the name +//math floor rounds a number down to the nearest whole number + +// Practice 3 +let students = ["A", "B", "C", "D"]; +for(let i=0; i= 90) { + return "A"; + } else if (average >= 80) { + return "B"; + } else if (average >= 70) { + return "C"; + } else if (average >= 60) { + return "D"; + } else { + return "F"; + } +} + +let average = calculateAverage(student.scores); +let grade = getFinalGrades(average); + +console.log("Name: " + student.name); +console.log("Average: " + average); +console.log("Grade: " + grade); + +//Strings are the easiest data type for me +//Arrays are the most confusing for me +//Arrays are collection of values of the same data type, objects have multiple different fields that can be different data types +// You would use arrays when grouping data of the same type, you would objects when grouping data with mutiple different fields that need to be grouped together