JavaScript playground
Write total(numbers) in the browser. The preview cannot read this site's cookies.
Write total(numbers) so total([2, 3, 5]) returns 10. The frame can run script and cannot read this site.
What this tool does
The playground asks you to write a function named total that adds an array of numbers. The check calls total([2, 3, 5]) and expects 10. The starter code uses reduce with a zero initial value, which already returns 10. Change it if you want to practise a loop. The preview is an iframe with the sandbox attribute allow-scripts. It can run the script you wrote. It is not given this site's cookies, storage, or DOM. A message event carries back ok and the value, or the error string. The score is pass or fail on that one call. It does not grade style, and it does not run a hidden test suite.
How to use it
Edit the function. Press Run. If the frame posts 10, the attempt passes. If it throws, the error text comes back and the attempt does not pass. A function that returns the string "10" is not the number 10, so check the type if you are surprised by a fail. Keep the function name total. The checker does not look for a different name.
Worked example
function total(numbers) { return numbers.reduce((sum, value) => sum + value, 0); } returns 10 for [2, 3, 5]. A loop that starts at zero and adds 2, then 3, then 5 also returns 10. A reduce with no initial value happens to return 10 on this array too, but an empty array would throw. The starter includes the initial zero for that reason. The frame cannot read your HiringBuddy session, so do not put a token in the editor expecting it to be secret from the script you yourself wrote. The script is yours. The jobs link on this page searches HiringBuddy for published roles matching “software”. An empty list means nothing published matched. It is not a comment on the wider market. A signed-in candidate can save the attempt on their profile. Saving is not an application, and it does not show the attempt to an employer. Employers see people who apply to their own jobs.
Questions
- What is the only test?
- total([2, 3, 5]) should return the number 10.
- Can the preview see my login?
- The iframe is sandboxed to scripts. It is not given this site's cookies.
- Does a style error fail the test?
- No. Only the returned value is checked.