Gold Pearl
Gold Pearl

Reputation: 23

How to convert this python code to Javascript

I don't want to run the Python code inside Javascript, I want to turn it completely into JS code. I have no idea about python, Can body can help me on this. Thank you.

print ("Please input the # of books you've read this year") 
BooksAlready=int(input())
print ("Please input the # of weeks that have already passed this year") 
WeeksAlready=int(input())
x=(78/52)
c=x*WeeksAlready-BooksAlready
if (BooksAlready/WeeksAlready)>x:
  print ("You're on point, go have some fun!")
else:
  print ("Go read, you piece of uneducated crap")
  print ("You have")
  print (c)
  print ("books left to read this week to get on point")

Upvotes: 1

Views: 4582

Answers (2)

Mohammed Rishad
Mohammed Rishad

Reputation: 335

Please check below links to know more about converters from python to js.

http://www.infoworld.com/article/3033047/javascript/4-tools-to-convert-python-to-javascript-and-back-again.html

Upvotes: 0

nick
nick

Reputation: 1207

This will run in the browser's js console. prompt will not work in node.js, you can access a commandline argument with process.argv.

console.log("Please input the # of books you've read this year");
console.log("Please input the # of weeks that have already passed this year");

var WeeksAlready=parseInt(prompt()),
BooksAlready=parseInt(prompt()), 
x=(78/52),
c=x*WeeksAlready-BooksAlready;

if (BooksAlready/WeeksAlready>x){
    console.log("You're on point, go have some fun!");
}
else{
   console.log ("Go read, you piece of uneducated crap");
   console.log ("You have");
   console.log (c);
   console.log ("books left to read this week to get on point"); 
}

Upvotes: 2

Related Questions