Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ <h1>Loops Exercises</h1>

<section id="menu">
<ul>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 3.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 3.2</button></li>
<li><button type="button" class="btn btn-primary" onclick="arrangeArray()">Example 3.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="highestNumber()">Example 3.2</button></li>
</ul>
</section>

Expand Down
41 changes: 32 additions & 9 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
" use strict ";
' use strict '

var display = document.getElementById("display");
var display = document.getElementById('display')

function yourFunctionName (){
display.innerHTML = "hello";
function arrangeArray () {
display.innerHTML = ''
const arrayOne = ['a', 'b', 'c']
const arrayTwo = ['1', '2', '3']
for (let i = 0; i < arrayOne.length; i++) {
display.innerHTML += arrayOne[i]
display.innerHTML += '<br/>' + arrayTwo[i] + '<br/>'
}
}

function example(){
var v = 3 +4;

display.innerHTML = v;
}
function format (number) {
let value = 0
if (number >= 10) value = number / 10
else if (number >= 100) value = number / 100
else if (number >= 1000) value = number / 1000
else return number
return Math.round(value)
}

function compare (a, b) {
const aFormatted = format(a)
const bFormatted = format(b)
if (aFormatted > bFormatted) return -1
if (aFormatted < bFormatted) return 1
return 0
}

function highestNumber () {
const numbers = [50, 2, 1, 9]
numbers.sort(compare)
display.innerHTML += numbers.join('')
}