edit-article
Home
Up
Delete
Article Name:
Article Description:
code-quiz-you-cant-code-javascript-under-pressure - time based javascript code tests
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">you can't code javascript under pressure</h1> <h2>[WHAT]</h2> <ol> <li>[] this short timed quiz was popular for a while in 2013 ish, coding questions got progressively harder as you worked through the questions</li> </ol> <h2>[WHY]</h2> <ol> <li>[] test your javascript coding skills in a time based scenario</li> </ol> <h2>[WHERE]</h2> <ol> <li><strong>[] TRY OUT THIS LEARNING TOOL</strong></li> <ol> <li><span style="text-decoration: line-through;">[] <a href="http://games.usvsth3m.com/javascript-under-pressure/" target="_blank">http://games.usvsth3m.com/javascript-under-pressure/</a> </span></li> <li><span style="display: inline !important; float: none; background-color: #ffffff; color: #000000; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;">[x] UPDATED][2019-11-24] looks like the quiz is no longer online at the original host, </span></li> </ol></ol> <h2>[WHEN]</h2> <ol> <li><strong>[] 2013-10-dd</strong></li> <ol> <li>[x] i completed 3/5 questions, was working the 4th, but not all tests were passing with my solution (edge cases), never attempted the fifth</li> </ol></ol> <h2>[EXAMPLE]</h2> <ol> <li><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-style: normal; font-variant: normal; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;">[] double the result</span></li> <li><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-variant: normal; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-style: normal; font-variant: normal; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;">[] determine if (odd?even) </span></span></li> <li><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-variant: normal; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-style: normal; font-variant: normal; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;">[] extract the filename extension</span></span></li> <li><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-variant: normal; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-style: normal; font-variant: normal; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;">[] find the Longest String - </span></span></li> <li><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-variant: normal; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="text-align: left; color: #000000; text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-style: normal; font-variant: normal; text-decoration: none; word-spacing: 0px; display: inline !important; white-space: normal; orphans: 2; float: none; -webkit-text-stroke-width: 0px; background-color: #ffffff;">[] Sum all integers - The description of the problem asks us to “sum all integers you find, anywhere”. Well, this nested array has integers in it, doesn’t it? How do we add these to the count without borking up our iteration over each array index?</span></span></li> </ol> <h2>[HOW-TO]</h2> <ol> <li>] see below for my solutions/notes/comments, also REF 002 </li> </ol> <h2>[REFERENCE]</h2> <ol> <li>[] leah verou posted her answers code to these tests on her blog</li> <li>[] <a href="http://zpalexander.com/you-cant-javascript-under-pressure/" target="_blank">http://zpalexander.com/you-cant-javascript-under-pressure/</a></li> </ol> <p> </p> <hr /> <h2><strong>1] function double the result</strong></h2> <p>double the argument and return the results</p> <p>function double(){</p> <p> return i*2; </p> <p>}</p> <h2><strong>2] function determine (odd?even) </strong></h2> <p>Return true or false depending on whether the number is even.<br />You can use console.log() and alert(); the results will show up here</p> <p>TIMER - 09:01 </p> <h2><strong>3] extract filename extension</strong></h2> <p> <br />function getFileExtension(i) {<br /> <br /> <br />// i will be a string, but it may not have a file extension.<br /> <br />// return the file extension (with no period) if it has one, otherwise false<br /> <br /> <br />var len = i.length;<br /> <br />var result = true;<br /> <br />var arr = [];<br /> </p> <p>/*<br /> <br />if ( i.indexOf('.') === undefined ){<br /> return false;<br /> }<br /> <br />*/<br /> <br />// grrrrrrrrrrrrrrrrr<br /> <br />// PRB WAS s first i.indexOf('.')<br />// if ( i.indexOf('.') && i.indexOf('.') >= 0 ){</p> <p>if ( i.indexOf('.') >= 0 ){<br /> var x = i.indexOf(".");<br /> <br /> if ( i.indexOf('.') >= 1){<br /> arr = i.split('.');<br /> return arr[1];<br /> }<br /> <br /> if (x === 0) { <br /> return i.slice(1);<br /> }<br /> }<br /> /* <br /> if ( i.indexOf('.')){<br /> arr = i.split('.');<br /> return arr[1];<br /> }<br /> if ( i.indexOf('.') === -1 ){<br /> result = false;<br /> return result;<br /> }<br /> */<br /> <br /> else{<br /> result = false;<br /> return result;<br /> //console.log("false");<br /> }</p> <p>}</p> <p><strong>TIMER = 87.20 - ouch, ouch, ouch</strong> <br />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?</p> <h2>4] find the longest string</h2> <p><br />function getUTF8ByteLength(s) {<br /> return unescape(encodeURIComponent(s)).length;<br />}</p> <p>function longestString(i) {<br /> // i will be an array.<br /> // return the longest string in the array<br /> var myArray = i;<br /> for (x=0; x < myArray.length; x++){<br /> myArray[x].len = myArray[x].length; <br /> }<br /> <br /> myArray.sort(function(a, b) {<br /> return a.len - b.len;<br /> });<br /> <br /> return myArray[myArray.length-1];<br />}</p> <p><br />function longestString(i) {<br /> // i will be an array.<br /> // return the longest string in the array<br /> var myArray = i;<br /> <br /> function getUTF8ByteLength(s) {<br /> return unescape(encodeURIComponent(s)).length;<br /> }<br /> <br /> <br /> for (x=0; x < myArray.length; x++){<br /> // myArray[x].len = myArray[x].length; <br /> myArray[x].len = getUTF8ByteLength(myArray[x]);<br /> }<br /> <br /> myArray.sort(function(a, b) {<br /> return a.len - b.len;<br /> });<br /> <br /> return myArray[myArray.length-1];<br />}</p> <p><strong>TIMER = 119.00 -abondoned</strong></p> <p>- 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</p> <h2>5] sum all integers</h2> <p> </p>