wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
cin >> a;
int a; cin >> a;
Declare variable.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$data = 87; if ($data = 87) {{}}
$data = 87; if ($data == 87) {{}}
Use ==.
PHP
List(58,35,84)
List(58,35,84)
Correct.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
for val in range(77) print(val)
for val in range(77): print(val)
Colon after for.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
fn render() -> i32 {{ 50 }}
fn render() -> i32 {{ 50 }}
Correct.
Rust
if (b = 78)
if (b == 78)
Use ==.
C++
if item = 50 then print('info') end
if item == 50 then print('info') end
Use ==.
Lua
name: output age: 79
name: output age: 79
Correct.
YAML
["output", 16]
["output", 16]
Correct.
JSON
local foo = 52
local foo = 52
Correct.
Lua
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
val count = 92; count = 52
var count = 92; count = 52
Use var for reassignment.
Scala
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
y == '75'
y === 75
Use strict equality.
JavaScript
name: info value: data,
name: info value: data
Remove comma.
YAML
int items[82]; items[82]=5;
int items[82]; if(82<82){{}} else items[82]=5;
Bounds check.
C++
class Order {{ int bar; }} obj.bar=5;
class Order {{ public int bar; }} obj.bar=5;
Make field public.
Java
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{'status':58, 'age' 32}}
{{'status':58, 'age':32}}
Colon missing.
Python
cin >> num;
int num; cin >> num;
Declare variable.
C++
let result = 69;
let result = 69;
Correct.
JavaScript
echo 'result'
echo 'result';
Add semicolon.
PHP
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(70);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(70);
Correct.
Node.js
let item = 'data'
let item = "data"
Double quotes.
Swift
WHERE name = '62'
WHERE name = 62
Don't quote integer.
SQL
arr(35)
if length(arr) >= 35, arr(35), end
Check length.
MATLAB
for i=1,10 do print(i) end
for i=1,10 do print(i) end
Correct.
Lua
$arr[81]
if ($arr.Count -gt 81) {{ $arr[81] }}
Check bounds.
PowerShell
var x = 54;
var x = 54;
Correct.
Dart
local count = 84
local count = 84
Correct.
Lua
values[36]
if values.indices.contains(36) {{ values[36] }}
Check index.
Swift
name: test id: data,
name: test id: data
Remove comma.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
val == '4'
val === 4
Use strict equality.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(12);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(12, () => console.log('listening'));
Add callback.
Node.js
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<input type='text' value='message'>
<input type='text' value='message' name='age'>
Add name attribute.
HTML
int[] values = new int[80]; values[80] = 5;
int[] values = new int[80]; if (80 < values.length) values[80] = 5;
Check bounds.
Java
if foo > 66 puts 'message'
if foo > 66 puts 'message' end
Add 'end'.
Ruby
<user><desc>data</desc><desc>8</desc></user
<user><desc>data</desc><desc>8</desc></user>
Add closing >.
XML
int b = 'message';
String b = 'message';
Type mismatch.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
UPDATE items SET age='hello' WHERE status=10
UPDATE items SET age='hello' WHERE status=10;
Add semicolon.
SQL
DELETE FROM products WHERE id=65
DELETE FROM products WHERE id=65;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
yield num
yield num
Correct yield.
Python
let msg = String::from("output"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("output"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let foo = 92; foo += 1;
let mut foo = 92; foo += 1;
Need mut to modify.
Rust
assert index > 80
assert index > 80
Correct.
Python
let z: number | null = null; z.toFixed(66);
let z: number | null = null; if(z!==null) z.toFixed(66);
Null check.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
h1 {{ font-size:71px color:#333; }}
h1 {{ font-size:71px; color:#333; }}
Add semicolon.
CSS
print 'result'
print 'result';
Add semicolon.
Perl
class User {{ int count; }} obj.count=5;
class User {{ public int count; }} obj.count=5;
Make field public.
Java
let mut temp=13; let ref1=&mut temp; let r2=&mut temp;
let mut temp=13; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (c = 86) {{}}
if (c === 86) {{}}
Use === for equality.
JavaScript
int items[9]; items[9]=5;
int items[9]; if(9<9){{}} else items[9]=5;
Bounds check.
C++
String name = 'hello';
String name = 'hello';
Correct.
Dart
arr[61]
if (arr.indices.contains(61)) arr[61]
Check index.
Kotlin
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
class Order def method end end
class Order def method end end
Correct.
Ruby
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
List(10,80,85)
List(10,80,85)
Correct.
Scala
print 'data'
print('data')
print needs parentheses.
Python
if (bar = 92)
if (bar == 92)
Use ==.
Scala
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
$data[92] = 5;
if (isset($data[92])) $data[92] = 5;
Check existence.
PHP
if (data = 96) {}
if (data == 96) {}
Use ==.
Dart
if val = 58 then print('output') end
if val == 58 then print('output') end
Use ==.
Lua
[18, 75, 32
[18, 75, 32]
Close bracket.
Python
test
test()
Add parentheses.
Kotlin
if [ $b = 18 ]; then
if [ "$b" = 18 ]; then
Quote variable.
Shell
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
'87' + 40
87 + 40
Avoid string coercion.
JavaScript
b = 98
b=98
No spaces.
Shell
{{"id":"value" "age":41}}
{{"id":"value", "age":41}}
Add comma.
JSON
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
if ($num = 77) {{}}
if ($num -eq 77) {{}}
Use -eq.
PowerShell
["result", 80]
["result", 80]
Correct.
JSON