I just had my therapy appointment. It was supposed to be yesterday, but something happened, and it didn’t happen. So the appointment was changed to today. Today, we were talking about trauma in high school, and the incident from the band came up. The therapist asked why Children Services and the police weren’t notified of the incident and said somebody should have been notified. I feel like the high school hid everything. Not that I care too much, as I didn’t want any further embarrassment. But if the school was supposed to report this, they didn’t do a good job and were pretty fucked up about them. I mean, when I found out what Mike did to Karissa, we first reported it to the police and children’s services. I was so embarrassed and ashamed about what had happened to me, and how the high school dealt with it was fucked up. And now I’m all worked up about this. This “going through my trauma” thing is difficult.
I want to read a book or play a game and forget all about the past. Instead, my head replays everything.
Speaking of books, I’m reading Gabriel’s Inferno. Almost every book I have read has been written by females, and I wanted to read one written by a male. And for some reason, I chose this one. It’s hard to finish and not for any reasons that you think. The format of the book could be more precise. The alternating first-person viewpoints were confusing. I’m not too fond of it. I can’t get into liking the characters. It’s not because the main character is a douchebag and the main female character is too perfect and “pure,” as the book tells you she is. She is in her mid-20s, but everyone talks to her as if she were 12. There is no reason behind their actions. There is no character development. I come to not care about what happens to these characters. And all the sap! I felt like I was drowning in maple syrup after the main characters finally got together. This reads like a fan fiction. I have nothing against fan fiction; some excellent ones are out there. And how the book was being written is alright. It is just the actual words the characters say to each other that are hard to believe. The main character is supposed to be 33, but he is written as a 50-year-old.
I’m trying to keep up with my reading, so I’m finishing this book. If another book comes in from the library, I may start reading that one instead. I don’t understand the good ratings from GoodReads. Many seem to love the main character, saying he is romantic rather than emotionally and mentally manipulating. I do wonder how it will end.
Oh, I’m caught up in the main scenario quests in Final Fantasy XIV. Now, I’m ready for the next expansion this summer.
JavaScript notes..
——————————————–
Calorie Counter
Step 17
Declare an isError variable and set it to false, but use let so you can reassign it later.
const calorieCounter = document.getElementById('calorie-counter'); const budgetNumberInput = document.getElementById('budget'); const entryDropdown = document.getElementById('entry-dropdown'); const addEntryButton = document.getElementById('add-entry'); const clearButton = document.getElementById('clear'); const output = document.getElementById('output'); let isError = false;
Step 18
Even though you set an input element to be a number, JavaScript receives a string value. You need to write a function to clean the string value and ensure you have a number.
Start by declaring a cleanInputString function that takes a str parameter.
function cleanInputString(str) { }
Step 19
You need to split your str into individual characters. You can use the split() method to do this.
The split() method splits a string into an array of substrings, and returns the new array. You can pass in an optional separator which tells the method where each split should happen.
For example, passing an empty string into the split method will split the string into an array of individual characters.
const str = ‘Hello World’;
const strArray = str.split(”);
// [“H”, “e”, “l”, “l”, “o”, ” “, “W”, “o”, “r”, “l”, “d”]
Split the string passed into the cleanInputString function into an array of individual characters and assign it to a variable named strArray.
function cleanInputString(str) { let strArray = str.split(''); }
Step 20
Declare a cleanStrArray variable and assign it an empty array. You will use this to store your valid number characters.
function cleanInputString(str) { const strArray = str.split(''); const cleanStrArray = []; }
Step 21
Use a for loop to iterate through each character in your strArray array.
function cleanInputString(str) { const strArray = str.split(''); const cleanStrArray = []; for (let i = 0; i < strArray.length; i++) { } }
Step 22
Within your loop, you need to check if the character in strArray at index i is not a +, -, or a space. If it is not, push it to the cleanStrArray.
You will need to check if the array ["+", "-", " "] does not include the current character. You can use a combination of the includes() method and the ! operator to do this.
The .includes() method returns true if the array contains the character, and false if not. The logical NOT operator (!) will return the opposite of the value of the .includes() method.
Here is an example:
const numbersArray = [1, 2, 3, 4, 5]
const number = 6
if (!numbersArray.includes(number)) {
console.log("The number is not in the array.")
}
function cleanInputString(str) { const strArray = str.split(''); const cleanStrArray = []; for (let i = 0; i < strArray.length; i++) { if (!["+", "-", " "].includes(strArray[i])) { cleanStrArray.push(strArray[i]); } } }
Step 23
While looping through the string works, creating a new array is inefficient for memory and runtime performance. Instead, you can use Regular Expressions (referred to as "regex") to match specific characters.
Regex in JavaScript is indicated by a pattern wrapped in forward slashes – for example:
const regex = /hello/;
Remove your existing code within the cleanInputString function. Declare a regex variable and assign it the value from the example above.
function cleanInputString(str) { let regex = /hello/; }
Step 24
The pattern you currently have will match the exact text hello, which is not what you want to match. You want to look for +, -, or spaces. Replace the pattern in your regex variable with \+- to look for plus and minus characters.
Note that you need to use the \ to escape the +, because a + has a special meaning in regular expressions.
function cleanInputString(str) { const regex = /\+-/; }
Step 25
In regex, shorthand character classes allow you to match specific characters without having to write those characters in your pattern. Shorthand character classes are preceded with a backslash (\). The character class \s will match any whitespace character. Add this to your regex pattern.
function cleanInputString(str) { const regex = /\+-\s/; }
Step 26
Your current pattern won't work just yet. /+-\s/ looks for +, -, and a space in order. This would match +- hello but would not match +hello.
To tell the pattern to match each of these characters individually, you need to turn them into a character class. This is done by wrapping the characters you want to match in brackets. For example, this pattern will match the characters h, e, l, or o:
const regex = /[helo]/;
Turn your +-\s pattern into a character class. Note that you no longer need to escape the + character, because you are using a character class.
function cleanInputString(str) { const regex = /[+-\s]/; }
Step 27
Regex can also take specific flags to alter the pattern matching behavior. Flags are added after the closing /. The g flag, which stands for "global", will tell the pattern to continue looking after it has found a match. Here is an example:
const helloRegex = /hello/g;
Add the g flag to your regex pattern.
function cleanInputString(str) { const regex = /[+-\s]/g; }
Step 28
Strings have a .replace() method which allows you to replace characters in the string with another string. .replace takes two arguments. The first is the character sequence to replace – this can either be a string or a regex pattern. The second is the string to replace that sequence with. For example, this would replace all instances of l with 1:
"hello".replace(/l/g, "1");
Use your regex to replace all instances of +, -, and a space in str with an empty string. Return this value.
function cleanInputString(str) { const regex = /[+-\s]/g; return str.replace(regex, ""); }