-
Notifications
You must be signed in to change notification settings - Fork 0
/
berries.js
49 lines (40 loc) · 2.04 KB
/
berries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$(() => {
$('#berry-btn').on('click', (event) => {
const userInput = $("input[type='text']").val();
$('#modal_screen').css('display', 'block');
$.ajax({
url: `https://pokeapi.co/api/v2/berry/${userInput}/`,
}).then((data) => {
console.log(data);
// API has no images for berries that I have found yet.
// let img = $('<img id ="picture">');
// img.attr('src', data.sprites.other.dream_world.front_default);
// img.appendTo('#modal_screen_data');
$('<h3>').html('Berry Name:').appendTo($('#modal_screen_data'));
$('<p>').html(data.name).appendTo($('#modal_screen_data'));
$('<h3>').html('Soil Dryness:').appendTo($('#modal_screen_data'));
$('<p>').html(data.soil_dryness).appendTo($('#modal_screen_data'));
$('<h3>').html('Growth Time:').appendTo($('#modal_screen_data'));
$('<p>').html(data.growth_time).appendTo($('#modal_screen_data'));
$('<h3>').html('Firmness:').appendTo($('#modal_screen_data'));
$('<p>').html(data.firmness.name).appendTo($('#modal_screen_data'));
$('<h3>').html('Size:').appendTo($('#modal_screen_data'));
$('<p>').html(data.size).appendTo($('#modal_screen_data'));
$('<h3>').html('Smoothness:').appendTo($('#modal_screen_data'));
$('<p>').html(data.smoothness).appendTo($('#modal_screen_data'));
$('<h3>').html('Flavors:').appendTo($('#modal_screen_data'));
for (let i = 0; i < data.flavors.length; i++) {
$('<p>')
.appendTo($('#modal_screen_data'))
.html(data.flavors[i].flavor.name);
}
});
const closeModal = () => {
$('#modal_screen_data').empty();
$('#modal_screen').css('display', 'none');
$('#modal').css('z-index', '-10');
userInput = $("input[type='text']").val('');
};
$('#close').on('click', closeModal);
});
});