JSFiddle - React, Tailwind, and code Playground
by wangtn18
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/q.js/1.4.1/q.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.2.0/chai.js"></script>
<!-- Mocha test output goes here. -->
<div id="mocha"></div>
JavaScript
mocha.setup('bdd');
var expect = chai.expect;
// Viết hàm để viết hoa chữ cái đầu của từng từ trong câu
function capitalize(str) {
var words = str.split(' ');
console.log(words);
console.log(words.length)
var c =[];
for (var word of words){
console.log(word);
var newWord= word.replace(word.charAt(0),word.charAt(0).toUpperCase());
console.log(newWord);
c.push(newWord);
console.log(c)
}
return c.join(' ')
}
describe('capitalize', function() {
it('capitalizes the first letter of every word in a sentence', function() {
expect(capitalize('hi there, how is it going?')).to.equal('Hi There, How Is It Going?');
});
it('capitalizes the first letter of every word in a sentence', function() {
expect(capitalize('i love breakfast at bill miller bbq')).to.equal('I Love Breakfast At Bill Miller Bbq');
});
it('capitalizes the first letter of every word in a sentence', function() {
expect(capitalize('xin chào')).to.equal('Xin Chào');
});
it('capitalizes the first letter of every word in a sentence', function() {
expect(capitalize('look, it is working!')).to.equal('Look, It Is Working!');
});
});
mocha.run();