creating quiz app

pull/1/head
Jen Looper 3 years ago
parent 61d875be4a
commit c0fbbaa04f

@ -0,0 +1 @@
node_modules

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Arpan Adhikari
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,33 @@
# Quizzes
These quizzes are the pre- and post-lecture quizzes for the web development for ml curriculum at https://aka.ms/ml-beginners
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
Credits: Thanks to the original version of this quiz app: https://github.com/arpan45/simple-quiz-vue

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,44 @@
{
"name": "quizzes",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-i18n": "^8.22.2",
"vue-router": "^3.4.9"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

@ -0,0 +1,8 @@
{
"routes": [
{
"route": "/*",
"serve": "/index.html"
}
]
}

@ -0,0 +1,105 @@
<template>
<div>
<nav>
<router-link class="navlink" to="/">Home</router-link>
<label for="locale">locale</label>
<select v-model="locale">
<option>en</option>
</select>
</nav>
<div id="app">
<h1>{{ $t("title") }}</h1>
<router-view>
<Quiz />
</router-view>
</div>
</div>
</template>
<script>
import Quiz from "@/components/Quiz.vue";
import messages from "@/assets/translations";
export default {
name: "App",
i18n: { messages },
components: {
Quiz,
},
data() {
return {
locale: "en",
};
},
watch: {
locale(val) {
this.$root.$i18n.locale = val;
},
},
created() {
if (this.$route.query.loc) {
this.locale = this.$route.query.loc;
}
},
};
</script>
<style>
html {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #252d4a;
}
nav {
background-color: #252d4a;
padding: 1em;
margin-bottom: 20px;
}
nav a {
color: white;
text-align: right;
}
.link {
display: list-item;
}
h1,
h2,
h3,
.message {
text-align: center;
}
.error {
color: red;
}
.card {
width: 60%;
border: #252d4a solid;
border-radius: 5px;
margin: auto;
padding: 1em;
}
.btn {
min-width: 50%;
font-size: 16px;
text-align: center;
cursor: pointer;
margin-bottom: 5px;
width: 50%;
font-size: 16px;
color: #ffffff;
background-color: #252d4a;
border-radius: 5px;
padding: 5px;
justify-content: flex-start;
align-items: center;
}
.ans-btn {
justify-content: center;
display: flex;
margin: 4px auto;
}
</style>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,10 @@
// index.js
import en from './en.json';
//export const defaultLocale = 'en';
const messages = {
en: en[0],
};
export default messages;

@ -0,0 +1,71 @@
<template>
<div class="card">
<div v-for="q in questions" :key="q.id">
<div v-if="route == q.id">
<h2>{{ q.title }}</h2>
<hr />
<h3 v-if="complete" class="message">{{ $t("complete") }}</h3>
<div v-else>
<h3 v-if="error" class="error">{{ $t("error") }}</h3>
<h2>
{{ q.quiz[currentQuestion].questionText }}
</h2>
<div>
<button
:key="index"
v-for="(option, index) in q.quiz[currentQuestion].answerOptions"
@click="handleAnswerClick(option.isCorrect)"
class="btn ans-btn"
>
{{ option.answerText }}
</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import messages from "@/assets/translations";
export default {
name: "Quiz",
data() {
return {
currentQuestion: 0,
complete: false,
error: false,
route: "",
locale: "",
};
},
computed: {
questions() {
return this.$t("quizzes");
},
},
i18n: { messages },
methods: {
handleAnswerClick(isCorrect) {
this.error = false;
let nextQuestion = this.currentQuestion + 1;
if (isCorrect == "true") {
//always 3 questions per quiz
if (nextQuestion < 3) {
this.currentQuestion = nextQuestion;
} else {
this.complete = true;
}
} else {
this.error = true;
}
},
},
created() {
this.route = this.$route.params.id;
this.locale = this.$route.query.loc;
},
};
</script>

@ -0,0 +1,14 @@
import Vue from 'vue';
import App from './App.vue';
Vue.config.productionTip = false;
import router from './router';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
});
new Vue({ i18n, router, render: (h) => h(App) }).$mount('#app');

@ -0,0 +1,34 @@
import Vue from 'vue';
import Router from 'vue-router';
import Home from '@/views/Home.vue';
import Quiz from '@/components/Quiz.vue';
import NotFound from '@/views/NotFound.vue';
Vue.use(Router);
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home,
},
{
path: '/quiz/:id',
name: 'Quiz',
component: Quiz,
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: NotFound,
meta: { title: 'Not Found' },
},
],
});
router.beforeEach((to, from, next) => {
next();
});
export default router;

@ -0,0 +1,26 @@
<template>
<div>
<router-link
v-for="q in questions"
:key="q.id"
:to="`quiz/${q.id}`"
class="link"
>
{{ q.title }}
</router-link>
</div>
</template>
<script>
import messages from "@/assets/translations";
export default {
name: "Home",
computed: {
questions() {
return this.$t("quizzes");
},
},
i18n: { messages },
};
</script>

@ -0,0 +1,5 @@
<template>
<div>
<p>Sorry, wrong number!</p>
</div>
</template>

@ -19,3 +19,11 @@ In these five lessons, you will explore data sourced from nature and create inte
### Credits
These visualization lessons were written with 🌸 by [Jen Looper](https://twitter.com/jenlooper)
🍯 Data for US Honey Production is sourced from Jessica Li's project on [Kaggle](https://www.kaggle.com/jessicali9530/honey-production). The [data](https://usda.library.cornell.edu/concern/publications/rn301137d) is derived from the [United States Department of Agriculture](https://www.nass.usda.gov/About_NASS/index.php).
🍄 Data for mushrooms is also sourced from [Kaggle](https://www.kaggle.com/hatterasdunton/mushroom-classification-updated-dataset) revised by Hatteras Dunton. This dataset includes descriptions of hypothetical samples corresponding to 23 species of gilled mushrooms in the Agaricus and Lepiota Family Mushroom drawn from The Audubon Society Field Guide to North American Mushrooms (1981). This dataset was donated to UCI ML 27 in 1987.

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save