Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Add basic text based rule #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class App extends Component {
}
{showAnswer &&
<div>
{getResult()}
{getResult(this.input.value)}
<input type="button" onClick={this.toggleShowAnswer} ref={(back) => {this.back = back;}} value="Back"/>
</div>
}
Expand Down
7 changes: 5 additions & 2 deletions src/results.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import * as Rules from "./rules";

export default function() {
export default function(value) {
if (Rules.Mac.getResult()) {
return <p>Get a PC</p>
return <p>Get a PC</p>;
} else if (Rules.Contribute.getResult(value)) {
window.location.href = "https://github.com/hoily/how-do-i";
return <p>Github</p>;
} else {
return <p>Don't</p>
}
Expand Down
12 changes: 9 additions & 3 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ const Rule = class Rule {
if(options.os != null) {
this.os = options.os
}
if (options.text != null) {
this.text = options.text;
}
}

getResult() {
if (this.os != null) {
getResult(input) {
if (this.text != null) {
return input.toLowerCase() === this.text.toLowerCase();
} else if (this.os != null) {
return useragent.getOS().name === this.os;
} else {
return false
}
}
}
};

export const Mac = new Rule({os: "Mac OS"});
export const Contribute = new Rule({ text: "contribute" });