1

I would like to change the output of my div into a JavaScript div that is inside array for example currently its I am getting the information from http://ipinfo.io. I would like to print it out instead in my dialog as the question is being asked and answer with You are located: IP: 193.945.32.21 Location: Japan, Tokyo! getting the data from your location. Or just my current location don't have to be IP.

My dialogue: {text: 'Your current location?', audio: 'music/becoming.ogg', response: input => 'You are located:' + (responce) + '!'},:

IP: 193.945.32.21 Location: Japan, Tokyo

I want it to be inside my dialog so when the question is asked

Your current location? It will respond You are located: IP: 193.945.32.21 Location: Japan, Tokyo!

let questions = [
  {text:'What is your name?', audio:'music/openmind.ogg', response : input => 'Hello ' + input + '!' },
  {text:'How old are you?', response : input => 'That means you were born in ' + (2017 - input) + '.'},
  {text:'Where are you from?', audio:'music/beone.ogg', response: input => 'You are from ' + (input) + '.'},
  {text: 'Do you eat healthy?', audio: 'music/becoming.ogg', response: input => 'Acording to my data you are eating ' + (input) + ' and that is healthy!'},
  {text: 'What is your time?', audio: 'music/becoming.ogg', response: input => 'Where I am located' + (new Date().toLocaleTimeString()) + 'that is the day!'},
  {text: 'What language do you speak', audio: 'music/becoming.ogg', response: input => 'Acording to me you speak: ' + language() + '!'},
  {text: 'Your current location?', audio: 'music/becoming.ogg', response: input => 'You are located:' + (responce) + '!'},


 ];
 let ipinfoResponse;
 $.get("http://ipinfo.io", function (response) {
  ipinfoResponse = response;
}, "jsonp");

let output = $('#output'),
    input = $("#input"),
    curQuestion;

function ask() {
  let qi = Math.floor(Math.random() *  questions.length); //depending on your needs, a check could be added if it's been asked directly before or only recycle questions when all are asked
  curQuestion = questions[qi];
  setOutput(curQuestion.text);
  input.val('');
}

ask(); //first call

function respond(){
  let q = curQuestion;
  if(q.audio)
    new Audio(q.audio).play();
  setOutput(q.response(input.val()));
  setTimeout(ask, 5000);
}

function setOutput(txt){
  output.html($('<h1>').text(txt));
}


$(document).keypress(function(e) {
  if (e.which == 13) {
    respond();
    return false;
  }
});

function language () {
  var userLang = navigator.language || navigator.userLanguage;
  return userLang
}

$.get("http://ipinfo.io", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#address").html("Location: " + response.city + ", " + response.region);
    $("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
   <link href="css/style.css" rel="stylesheet">
	 <img src="http://i3.kym-cdn.com/photos/images/original/001/138/377/fcc.gif" class="img-responsive center-block" alt="ffc.gif">
	 <h1 class="text-center">Hello I am ZENYATTA!</h1>
	 <br> <br>
	 <div class="container">
<div class="well">
<div id="output"></div>
</div>

    <div class="col-md-2 col-md-offset-5">
			<div class="form-group">
			  <label>Responce:</label>
			  <input type="text" class="form-control" id="input" value="">
			</div>
		</div>


    <div id="ip"></div>
    <div id="address"></div>

</div>


<!-- jquery for enter key press -->

<script src="https://code.jquery.com/jquery-3.0.0.js" integrity="sha256-jrPLZ+8vDxt2FnE1zvZXCkCcebI/C8Dt5xyaQBjxQIo=" crossorigin="anonymous"></script>
<script src="js/s.js"> </script>

5
  • Where's your dialogue? Commented Feb 14, 2017 at 20:18
  • @Connum the questions array. Commented Feb 14, 2017 at 20:20
  • @Connum {text: 'Your current location?', audio: 'music/becoming.ogg', response: input => 'You are located:' + (responce) + '!'}, Commented Feb 14, 2017 at 20:21
  • That doesn't make any sense... I don't really understand what you are trying to achieve... For me, when I execute the snippet, I see my ip and location below the input field. Isn't that what you want? Commented Feb 14, 2017 at 20:22
  • @Connum What I want is when the question popup in the field "Your current location?" the user types in what ever he wants and it responds with ip and location in the white field and not on the bottom off the screen. Commented Feb 14, 2017 at 20:24

1 Answer 1

1

All you have to do is just add {text: 'Your current location?', audio: 'music/becoming.ogg', response: input => 'You are located:' + (document.getElementById('address').innerHTML) + '!'}, {text: 'You know you ip adress?', audio: 'music/becoming.ogg', response: input => 'You ip adress is:' + (document.getElementById('ip').innerHTML) + '!'}, To get the id refrence!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.