Bài tập Thêm "PY" trước một chuỗi
by wangtn18
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/5.2.0/mocha.css">
<script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.3.0/chai.min.js"></script>
<div id="mocha"></div>
JavaScript
mocha.setup("bdd");
var expect = chai.expect;
function pyString(String) {
// Viết hàm pyString để tạo chuỗi mới thêm "Py" trước chuỗi nhập vào. Nếu chuỗi đã cho đã bắt đầu bằng "Py" thì hãy trả về chuỗi gốc (không cần thêm).
// Tham số:
// - String: chuỗi nhập vào lúc đầu.
if (String.charAt(0)==='P' && String.charAt(1)==='y'){
return String;
} else return newString= 'Py'+String;
}
describe('pyString', function () {
it('Should return a new String with "PY" in front of the String', function () {
expect(pyString("Coders Tokyo")).to.equal("PyCoders Tokyo");
});
it('If the font of the String has "Py", return this String', function () {
expect(pyString('PyHello')).to.equal('PyHello');
});
});
mocha.run();