-
Notifications
You must be signed in to change notification settings - Fork 340
Bonfire Convert HTML Entities
Rafael J. Rodriguez edited this page Jan 6, 2017
·
2 revisions
Created by Rafase282
Github | FreeCodeCamp | CodePen | LinkedIn | Website | E-Mail
- Difficulty: 2/5
Convert the characters "&", "<", ">", '"' (double quote), and "'" (apostrophe), in a string to their corresponding HTML entities.
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
function convert(str) {
// :)
return str;
}
convert('Dolce & Gabbana');
- You have to create a program that will convert HTML entities from string to their corresponding HTML entities. There are only a few so you can use different methods.
- You can use regular Expressions however I didn't in this case.
- You will benefit form a chart with all the html entities so you know which ones are the right ones to put.
- You should separate and string and work with each character to convert the right ones and then join everything back up.
Solution ahead!
function convert(str) {
// Split by character to avoid problems.
var temp = str.split('');
// Since we are only checking for a few HTML elements I used a switch
for (var i = 0; i < temp.length; i++) {
switch (temp[i]) {
case '<':
temp[i] = '<';
break;
case '&':
temp[i] = '&';
break;
case '>':
temp[i] = '>';
break;
case '"':
temp[i] = '"';
break;
case "'":
temp[i] = ''';
break;
}
}
temp = temp.join('');
return temp;
}
- Read comments in code.
Thanks for visiting, if you like this please feel free to star my repo, follow me or even contact me about contributing as it will be a lot of work and having help would be cool.
- HTML5 and CSS
- Responsive Design with Bootstrap
- Gear up for Success
- jQuery
- Basic JavaScript
- Object Oriented and Functional Programming
- Basic Algorithm Scripting
- Basic Front End Development Projects
- Intermediate Algorithm Scripting
- JSON APIs and Ajax
- Intermediate Front End Development Projects
- Claim Your Front End Development Certificate
- Upper Intermediate Algorithm Scripting
- Automated Testing and Debugging
- Advanced Algorithm Scripting
- AngularJS (Legacy Material)
- Git
- Node.js and Express.js
- MongoDB
- API Projects
- Dynamic Web Applications
- Claim Your Back End Development Certificate
- Greefield Nonprofit Project 1
- Greefield Nonprofit Project 2
- Legacy Nonprofit Project 1
- Legacy Nonprofit Project 2
- Claim your Full Stack Development Certification
- Whiteboard Coding Interview Training
- Critical Thinking Interview Training
- Mock Interview 1
- Mock Interview 2
- Mock Interview 3