double the argument and return the results
function double(){
return i*2;
}
Return true or false depending on whether the number is even.
You can use console.log() and alert(); the results will show up here
TIMER - 09:01
function getFileExtension(i) {
// i will be a string, but it may not have a file extension.
// return the file extension (with no period) if it has one, otherwise false
var len = i.length;
var result = true;
var arr = [];
/*
if ( i.indexOf('.') === undefined ){
return false;
}
*/
// grrrrrrrrrrrrrrrrr
// PRB WAS s first i.indexOf('.')
// if ( i.indexOf('.') && i.indexOf('.') >= 0 ){
if ( i.indexOf('.') >= 0 ){
var x = i.indexOf(".");
if ( i.indexOf('.') >= 1){
arr = i.split('.');
return arr[1];
}
if (x === 0) {
return i.slice(1);
}
}
/*
if ( i.indexOf('.')){
arr = i.split('.');
return arr[1];
}
if ( i.indexOf('.') === -1 ){
result = false;
return result;
}
*/
else{
result = false;
return result;
//console.log("false");
}
}
TIMER = 87.20 - ouch, ouch, ouch
SUCCESS! All tests passed. You've used 87:20 so far. Well done! Top work, that was tricky. Two challenges left! Ready to start the clock again?
function getUTF8ByteLength(s) {
return unescape(encodeURIComponent(s)).length;
}
function longestString(i) {
// i will be an array.
// return the longest string in the array
var myArray = i;
for (x=0; x < myArray.length; x++){
myArray[x].len = myArray[x].length;
}
myArray.sort(function(a, b) {
return a.len - b.len;
});
return myArray[myArray.length-1];
}
function longestString(i) {
// i will be an array.
// return the longest string in the array
var myArray = i;
function getUTF8ByteLength(s) {
return unescape(encodeURIComponent(s)).length;
}
for (x=0; x < myArray.length; x++){
// myArray[x].len = myArray[x].length;
myArray[x].len = getUTF8ByteLength(myArray[x]);
}
myArray.sort(function(a, b) {
return a.len - b.len;
});
return myArray[myArray.length-1];
}
TIMER = 119.00 -abondoned
- this did not pass all tests, one test where string contains chinese characters indicates that the string with chinese characters (3) is longer then another string 'world' with 5 characters, likely some utf-8 encoding
ID: 2585
NAME: code-quiz-you-cant-code-javascript-under-pressure
DESCRIPTION: code-quiz-you-cant-code-javascript-under-pressure - time based javascript code tests
AUTHOR: article.author/s
EDITOR: article.editor/s
PUBLISHER: article.publisher/s
STATUS: Write
PRIORITY: -5
OWNER ID: 75