Using the below javascript to run my chrome extension. When the phone number is not in the right format then the chrome extension throws the right output. But when the phone number is in the correct format then chrome extension doesnt throw any output. Trying to put the phone number as 555-858-8585
var pbValues = {
projectName : 'kittenbook',
versionNumber : '0.0.1',
areaCodes: {
'408': 'Silicon Valley',
'702': 'Las Vegas',
'801': 'Northern Utah',
'765': 'West Lafayette',
'901': 'Memphis',
'507': 'Rochester, MN'
},
currentDate : new Date(),
// currentTime will look like '2014-01-25 at 14:45:12'
currentTime : currentDate.getFullYear() + '-' + // Set year
(currentDate.getMonth() + 1) + '-' + // Set month
currentDate.getDate() + ' at ' + // Set day of the month
currentDate.getHours() + ' : ' + // Set hours (military time)
currentDate.getMinutes() + ' : ' + // Set minutes
currentDate.getSeconds() // Set seconds
};
var userName = prompt ('Hello, what\'s your name?');
var phoneNumber = prompt ('Hello' + userName + ',what\'s your phone number?');
var phoneNumberPattern = /1?-?\(?\d{3}[\-\)]\d{3}-\d{4}/;
var output = '<h1>Hello, ' + userName + '!</h1>';
if (phoneNumberPattern.test(phoneNumber)) {
output = output + '<p>' + pbValues.projectName + ' ' + pbValues.versionNumber
+
' viewed on: ' + pbValues.currentTime + '</p>';
} else {
output = output + '<h2> That phone number is invalid: ' + phoneNumber;
}
document.body.innerHTML = output;
Aucun commentaire:
Enregistrer un commentaire