My journey through the 100 days of code! Day 8-14

My journey through the 100 days of code! Day 8-14

Day 8: Another project day during BootCamp! This time we made a roman numeral converter. At first, it was confusing, but once I heard the logic it was very similar to a change counter I made for CS50. Is it just me or is it the first logical steps of most problems that are the hardest to figure out? The main way to solve this problem was through while loops which then were converted into an object to look at the number that was inputted and print out the correct roman numerals based on the logic that was coded. Below is a snippet of what the code looks like.

Using while loops

const function numeralConverter = (num) => {
let result = '';
    while (num >= 10){
          result += 'X'
          num -= 10;
     }
     while (num >= 9){
          result += 'IX';
          num -= 9;
     } 
     while (num >= 5){
      result += 'V'
      num -= '5'
      }
}

I will stop it here, but the logic behind the while loop is to check if the number that was inputted and check if it is above ten. If it is, then subtract the number that is checking (to prevent infinite loops) and put the roman numeral in the result variable. Keep in mind that is the order of your loops matters, for this to work it has to be from highest number to lowest.

using Class/Object approach

// creating an object that stores the values of the number and and empty string that the numeral will be placed in
class NumeralConverter {
    //constructor has to be called to create and intiliaze the object.
  constructor(numberToConvert) {
    //this is refereing to the object is it apart of which is NumeralConverter
    this.value = numberToConvert;
    this.numeral = '';
  }
//function written that takes the symbol(the roman numeral) and the value
  processNumeral(symbol, symbolValue) {
    while (this.value >= symbolValue) {
      this.numeral += symbol;
      this.value -= symbolValue;
    }
  }
}
function convertToRoman(num) {
// Starting from Highest number to lowest
// This allows the stacks to properly execute
  // X: 10
  // V: 5
  // I: 1
// creating an instance of the NumeralConverter object
  const converter = new NumeralConverter(num);
  // console.log(converter);
  //calling the function with the roman symbol and the value is for
  converter.processNumeral('X', 10);
  converter.processNumeral('IX', 9);
  converter.processNumeral('V', 5);
  converter.processNumeral('IV', 4);
  converter.processNumeral('I', 1);
  console.log(converter);
  return converter.numeral;

I am still fairly new to classes but from what I understand, you are creating a class that holds the function and values pairs and provides the logic when called upon.

Day 9: I rested this day to prevent some burnout. I was starting to feel a little sluggish and unmotivated from last week, so I took a much-needed break to play some VR games and chill. Not much coding other than doing some Edabit practice on and off throughout the day.

Day 10: Coming out with a bang today! Woke up early (To my standards) and started a new project with a collaborator which has sparked some motivation to move forward! We are using Frontend Mentor to provide the project ideas. If you haven't heard of Frontend Mentor you should definitely check it out! It is a site where you can make projects and they provide most of the source files which is such a relief. I'll have to write a blog post about it once I finish the current task. But, I am extremely excited to work with someone collaboratively on a project. We are both learners on about the same levels which are going to be excellent in being able to edify our learning together. I am also trying to get the wife to join in and help some too.

Days 11-12: Strayed off the JavaScript path and worked on some Python stuff. I am working off a Twitch Plays Python code, but I am reworking it to hopefully play Super Auto Pets. Overall I think Python is okay, I just don't like the strict indentations and ways you write the logic. I prefer the way you write logic and loops the way you do in JS. I also worked a little bit on my group project, but other than that I have been coding less this week to take an easy break. I will have to create a blog post about that as well. It is super interesting!

day 13 Learned some debugging techniques during my Bootcamp. A very basic debugging technique is to log or print pieces of your code that you want to see change, or if something is going wrong, console log/ print where you think the error is. I also have started an accordion project from Frontend mentor and hope to complete a project a week if possible. I am starting in the newbie section and going up.

day 14 This day was pretty much a review day. In my Bootcamp, we went over array and object methods.

Common array methods

arr.push() //adds an item to the end of the array.
arr.unshift() //adds an item to the beginning of the array.
arr.pop() //removes from an item the end.
arr.shift() //removes from an item the beginning.
arr.splice(index, quantity) //removes any number of consecutive items from an array.
arr.slice(startingIndex, endingIndex) //Copies the items from the array.

I also learn about the spread operator (...arr).

Common object methods

You can create objects by calling an object through dot or bracket notation.

const fruit = {
apple: true,
banana: true
}
fruit.kiwi = true
fruit.['grapefruit'] = false

If you want to check certain properties in an object you can use the

const fruit{
type: 'large',
name: 'watermelon',
sweet: true
}
fruit.hasOwnProperty('name')
//or
in
console.log('type' in fruit)

will return a boolean value. You can also use

Object.key(fruit)

to see the key or all of the values of the object. Lastly, I frustratingly worked on my accordion project.

Thank you so much for reading my blog! I hope I didn't butcher too many of these concepts. Comment below if I missed anything or if any of my info is misleading.

If you want to follow my journey follow my Twitter.