-
Notifications
You must be signed in to change notification settings - Fork 21
Week 3 class assignment Joann Cahill #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1c108fe
ca66bb8
fd03493
97801bc
f8d7569
08e71ec
2428c05
9150d4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,54 @@ | |
// $ end of line | ||
|
||
// check testPhoneNumber | ||
|
||
console.log('Result for validation of phone number') | ||
|
||
function testPhoneNumber(phone) { | ||
const regex = /^\(\d{3}\)[-\s]\d{3}[-\s]\d{4}$/; | ||
//validate whether phone number matches regex format | ||
if (phone.match(regex)) { | ||
return ('true'); | ||
} else { | ||
return ('false'); | ||
|
||
} | ||
|
||
}; | ||
//run function with parameters | ||
console.log('Phone number is valid') | ||
console.log(testPhoneNumber('(206) 333-4444')); // should return true | ||
console.log('Phone number is not valid') | ||
console.log(testPhoneNumber('(206) 33-4444')); // should return false, missing a digit | ||
|
||
|
||
// 1. Create a function parsePhoneNumber that takes in a phoneNumber string | ||
// in one of the above formats. For this, you can *assume the phone number | ||
// in one of the above fparsePhoneNumberormats. For this, you can *assume the phone number | ||
// passed in is correct*. This should use a regular expression | ||
// and run the exec method to capture the area code and remaining part of | ||
// the phone number. | ||
// Returns an object in the format {areaCode, phoneNumber} | ||
console.log('Result for parsing of phone number'); | ||
|
||
function parsePhoneNumber(phone) { | ||
|
||
//parse area code | ||
const regexAreaCode = /\d{3}/g; | ||
let parsedAreaCode = regexAreaCode.exec(phone); | ||
// console.log(parsedAreaCode); | ||
|
||
|
||
//find phone nubers | ||
const regexPhone = /\d{3}[-\s]\d{4}/; | ||
let parsedPhone = regexPhone.exec(phone); | ||
let parsedPhone2 = parsedPhone[0].replace('-', ''); | ||
// console.log(parsedPhone); | ||
// console.log(parsedPhone2); | ||
|
||
//create format to be used in return statement | ||
let phoneNumbers = (`areaCode: ${parsedAreaCode}, phoneNumber: ${parsedPhone2} `) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very near the mark, but this is an important distinction . . . the goal is to return an object with the 2 values . . . here we are returning a string! I know it's a tad trivial seeming with this exercise, but having keen intentionality of types is a powerful skill to hone. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refer to lines 75 and 78 for a glimpse of how the return value should look. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also worth mentioning, this use of parenthesis around the string is not necessary |
||
// console.log(phoneNumbers); | ||
return phoneNumbers; | ||
}; | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,26 @@ | |
// - should have a method accelerate that logs to the console | ||
// `${name} moving to ${topSpeed}` | ||
|
||
class SpaceShip { | ||
constructor(name, topSpeed) { | ||
this.name = name; | ||
this.topSpeed = topSpeed; | ||
|
||
} | ||
|
||
usetopSpeed(){ | ||
const{name, topSpeed} = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha! Yes, this destructuring from |
||
console.log( `${this.name} moving to ${this.topSpeed}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we don't use the destructured values, it becomes moot. You can probably see in VSCode that |
||
} | ||
|
||
} | ||
|
||
|
||
// 2. Call the constructor with a couple ships, | ||
// and call accelerate on both of them. | ||
|
||
const spaceX = new SpaceShip('Dragon', '5,770 mph'); | ||
spaceX.usetopSpeed(); | ||
|
||
const blueOrigin = new SpaceShip('New Shepard', '2,217 mph'); | ||
blueOrigin.usetopSpeed(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately by undoing the bit of boilerplate that tests the
logReceipt()
function we sort of lose our way as to what is being exercised. The implementation above has become brittle and not re-usable . . it's a one-use function that entirely relies upon some external state nameditems
. . . What we're trying to get to is a function that can be passed any number of menu item objects (as the beginning file has as its test case)Try again, and be sure that the
logReceipt
function can take an undetermined number of inputs . . . . remember the 'spread' operator!