-
Clone this repo. Please write your code in
script.js
. You are encouraged to use ES6. -
In this directory, run:
$ python -m SimpleHTTPServer
. Open localhost:8000 to previewindex.html
. Remember to refresh the page after updating the code. -
To submit, please push the repo to your Github and notify us.
-
Write a constructor function named Smartlink that is initialized with 2 parameters: a) An auction ID in string form; b) A DOM element. Assign this DOM element to Smartlink
element
attribute. -
Smartlink has a method
validAuctionId()
that validates that the auction ID is a valid integer and returns a bool.
// Valid
'1235265680'
'97627'
// Invalid
'abcd'
'123abc'
- Smartlink has a
runAuction()
method that returns a promise that resolves with:
{
data: {
destination_url: 'http://merchant.example/product/1',
merchant_name: 'Sephora',
product_name: 'Highlighter brush',
price: '15.89',
}
}
-
Smartlink has a
rewriteLink(URL, linkText)
method, which takes two strings as parameters. It updates the href and text of its element with these new values. -
Write a constructor function named Jstag. It has a function called
findAllSmartlinks()
that is called on initialization. -
findAllSmartlinks()
finds all the Smartlink elements on the page, which are anchor elements with hrefs in the form ofhttps://shop-links.co/123456789
, where123456789
is the auction ID (hint: utilize Smartlink's validAuctionId function). Save the valid Smartlinks in an arraythis.smartlinks
.
// Valid links
'https://shop-links.co/98776543210'
'//shop-links.co/9877654321'
'shop-links.co/9877654323'
// Invalid
'https://shop-links.co/123invalid'
'shop-links.us/98776543210'
- Jstag has a method called
runAllSmartlinks()
. It loops through the smartlinks array and callrunAuction()
on each Smartlink. Then callrewriteLink()
using the data returned byrunAuction()
to update the Smartlink element.
- Smartlink href => destination URL
- Smartlink text => "Product Name, $Price at Merchant Name".
- Don't rewrite the Smartlink if the auction ID isn't valid. To verify that your code is working, check that "SMARTLINK 1" and "SMARTLINK 2" are overwritten with "Highlighter brush, $15.89 at Sephora". "INVALID SMARTLINK" and "RANDOM LINK" should not be updated.