Initializing
Liveweave
Web
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
frame_source
Python Playground
New
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<!DOCTYPE html> <html> <head> <title>HTML, CSS and JavaScript demo</title> </head> <body> <!-- Start your code here --> <div>All approaches to summing should add up to 5:</div> <ul> <li>For In: <span id="forin">hi</span></li> <li>For Each: <span id="foreach">hi</span></li> <li>Reduce: <span id="reduce">hi</span></li> <li>Babel translation of for-of: <span id="forofbabel">hi</span></li> </ul> <!-- End your code here --> </body> </html>
#output { font-size: 60px; }
var totalItems, sum, type, value; totalItems = []; totalItems[0] = 3; totalItems[1] = 2; totalItems.__ob__ = new Object(); Object.defineProperty(totalItems, '__ob__', { enumerable: false, writable: true, configurable: true }); sum = 0; for (type in totalItems) { value = totalItems[type]; sum += value; } document.getElementById('forin').innerHTML = sum; sum = 0; totalItems.forEach(function(item) { sum += item; }); document.getElementById('foreach').innerHTML = sum; sum = 0; sum = totalItems.reduce(function(t, s) { return t + s; }); document.getElementById('reduce').innerHTML = sum; sum = 0; var foo = totalItems; // From https://babeljs.io/docs/en/babel-plugin-transform-for-of var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = foo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var i = _step.value; sum += _step.value; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } document.getElementById('forofbabel').innerHTML = sum;