Skip to content

Commit

Permalink
Allow users to proceed through scales up and down
Browse files Browse the repository at this point in the history
  • Loading branch information
bychen9 committed Aug 7, 2019
1 parent ceb4e43 commit a9c4976
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions first-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let audio = null;
let mediaRecorder = null;
let body = document.querySelector("body");
let count = 0;

makeRecordButton();

function record() {
Expand Down
54 changes: 54 additions & 0 deletions scales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
let fileName = location.href.split("/").slice(-1);
let base = localStorage.getItem('baseNote');
let body = document.querySelector("body");
let text = document.createElement("p");
let node = document.createTextNode("Your base note was " + base + ".");
text.append(node);
body.insertBefore(text, body.childNodes[3]);

let upNotes = ["A", "B", "C", "D", "E", "F", "G"];
let downNotes = ["G", "F", "E", "D", "C", "B", "A"];
let baseIndex;
if (fileName[0] == "second-step.html") {
baseIndex = upNotes.findIndex(element => {
return element === base.charAt(0);
});
} else {
baseIndex = downNotes.findIndex(element => {
return element == base.charAt(0);
});
}

let i = 1;

let octaveNumber = base.charAt(1);
function nextNote() {
let note;
if (fileName[0] == "second-step.html") {
note = upNotes[(baseIndex + i) % 7];
if (note === "A") {
octaveNumber++;
}
} else {
note = downNotes[(baseIndex + i) % 7];
if (note === "G") {
octaveNumber--;
}
}
let singText = document.createElement("p");
let sing = document.createTextNode("Now, try to sing " + note + octaveNumber + ".");
singText.append(sing);
singText.setAttribute("id", "noteToSing");
body.insertBefore(singText, body.childNodes[4]);
i++;
}
nextNote();

let pass = document.getElementById("pass");
pass.onclick = function() {
let noteToSing = document.getElementById("noteToSing");
if (noteToSing != null) {
noteToSing.parentNode.removeChild(noteToSing);
}
nextNote();
}
4 changes: 3 additions & 1 deletion second-step.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<h2>Second Step: Sing Higher</h2>
<body>
<p>Sing from your base note to the top of your vocal range.</p>
<button id="pass">Pass</button>
<button id="next" onclick = "location.href = 'third-step.html'">Next Step</button>
</body>
<script src="second-step.js"></script>
<script src="scales.js"></script>
</html>
6 changes: 0 additions & 6 deletions second-step.js

This file was deleted.

13 changes: 13 additions & 0 deletions third-step.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>Third Step</title>
<head>
<h2>Third Step: Sing Lower</h2>
<body>
<p>Sing from your base note to the bottom of your vocal range.</p>
<button id="pass">Pass</button>
</body>
<script src="scales.js"></script>
</html>

0 comments on commit a9c4976

Please sign in to comment.