Skip to content
Open
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="combineArrays(['a', 'b', 'c'], [1,2,3])">Example 3.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="formLargestNum([50, 2, 1, 9])">Example 3.2</button></li>
</ul>
</section>

Expand Down
45 changes: 37 additions & 8 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
" use strict ";
' use strict '

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

function yourFunctionName (){
display.innerHTML = "hello";
display.innerHTML = "hello"
}

function example () {
var v = 3 + 4
display.innerHTML = v
}

function combineArrays(arrOne, arrTwo) {
let arrCombined = []
for (let i = 0; i < arrOne.length; i++) {
arrCombined.push(arrOne[i])
arrCombined.push(arrTwo[i])
}
display.innerHTML = arrCombined
}

function getFirstDigit (num) {
let digitString = ('' + num)[0]
let digit = parseInt(digitString)
return digit
}

function compare (numOne, numTwo) {
const digitOne = getFirstDigit(numOne)
const digitTwo = getFirstDigit(numTwo)
if (digitOne < digitTwo) return 1
if (digitOne > digitTwo) return -1
else return 0
}

function formLargestNum (arrPosInt) {
console.log(arrPosInt)
arrPosInt.sort(compare)
display.innerHTML += arrPosInt.join('')
}

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

display.innerHTML = v;
}